-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlearn.js
52 lines (52 loc) · 1.29 KB
/
learn.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// types by interface
var myName = "jayesh";
// use in object
var user = {
name: "jayesh",
age: 23
};
// use in class
var UserAccount = /** @class */ (function () {
function UserAccount(name, age) {
this.name = name;
this.age = age;
}
return UserAccount;
}());
var userobj1 = new UserAccount("Murphy", 1);
// or
var NewUserAccount = /** @class */ (function () {
function NewUserAccount(name, age) {
this.name = name;
this.age = age;
}
return NewUserAccount;
}());
var userobj2 = new NewUserAccount("Murphy", 1);
// return values and args to function
function add(a, b) {
return a + b;
}
var myUser = function (user) {
user.name = "sumeet";
return user;
};
var currName = "jayesh";
currName = 12;
function getLength(obj) {
return obj.length;
}
// array type
var arr = ['one', 'two', 'three'];
var arr2 = ["one", "two", "three"];
// object is a string, because we declared it above as the variable part of Backpack.
var object = backpack.get();
// Since the backpack variable is a string, you can't pass a number to the add function.
backpack.add("wild craft");
// tuple
var myArr = [12, "jayesh", true];
// type assertion
// explicitly tell typescript to treat value as another type or entity
var cid = "jayesh";
var newId = cid;
newId = 1;