-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
89 lines (89 loc) · 1.92 KB
/
Copy pathapp.js
File metadata and controls
89 lines (89 loc) · 1.92 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//String
var myName = 'Max';
//Number
var myAge = 27;
//boolean
var hasHobbies = false;
//assing types
var myRealage;
myRealage = 27;
myRealage = '27';
var myRealage2;
myRealage2 = 37;
//Array of string
var hobbies = ["cooking", "Sport"];
console.log(typeof hobbies);
console.log(hobbies[0]);
//Array of any
var hobbies2 = ["cooking2", "Sport2"];
hobbies2 = [100];
console.log(typeof hobbies);
console.log(hobbies[0]);
//tuples (array with mix type)
var address = ["telaviv", 99]; //order is inportent
//Emun
var Color;
(function (Color) {
Color[Color["Gray"] = 0] = "Gray";
Color[Color["Green"] = 1] = "Green";
Color[Color["Blue"] = 2] = "Blue"; //2
})(Color || (Color = {}));
var myColor = Color.Green;
console.log(myColor); // will print 1
//any
var car = "BMW";
console.log(car);
car = { brand: "BMW", model: 1988 };
console.log(car);
//------------------------------------------------------------------------------------
//Functions
function returnMyMame() {
return myName;
}
console.log(returnMyMame());
//void
function sayHello() {
console.log("Hello");
}
//arguments type
function multiply(value1, value2) {
return value1 * value2;
}
//function type
var myMultiply; //able to defind which type of function may hold
myMultiply = multiply;
console.log(myMultiply(5, 10));
//Objects
//In objects the order my be change
var userData = {
name: "bebe",
age: 60
};
//complex object
var complex = {
data: [100, 2, 5],
output: function (all) {
return this.data;
}
};
var complex2 = {
data: [100, 2, 5],
output: function (all) {
return this.data;
}
};
//union types
var myRealRealAge = 24; //Number or String
myRealRealAge = "27";
myRealRealAge = 27;
// check types
var finalValue = 30;
if (typeof finalValue == "number") {
console.log("the type is number");
}
//Nullable types
var canBeNull = 12;
canBeNull = null;
var alsoCanBeNull;
alsoCanBeNull = null;
//# sourceMappingURL=app.js.map