-
Notifications
You must be signed in to change notification settings - Fork 0
/
differentFromJS.js
64 lines (64 loc) · 1.39 KB
/
differentFromJS.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
53
54
55
56
57
58
59
60
61
62
63
64
// tsc to compile the ts file
console.log("Hello TS");
// 1 data types
// number
// string
// boolean // there is no truthy and false values
function add(n1, n2, is) {
if (is)
return n1 + n2;
}
var num1 = "5"; // you cannot assign with another datatype once it assing with a datatype
var num2 = 2.8;
var is = true;
console.log(add(+num1, num2, is));
// Object
var person = {
name: "Abhishek",
age: 21
};
console.log(person.name);
// console.log(person.some) // you cannot access key which is not in object
var person1 = {
name: "Abhishek",
age: 21
};
console.log(person1);
// console.log(person1.name) // you cannot do this if you are specific to the object
var person2 = {
name: "Abhi",
age: 21,
some: "red",
roll: [4, "a"]
};
person2.roll.push("ok");
console.log(person2.roll);
var perA = {
money: [3, 5],
book: ["ok", 5, true, "red"]
};
// Arrays
var arr = [4.6, 4, 6];
// tuple
var tuple1 = [1, "red"];
//Enum
var Enum;
(function (Enum) {
Enum[Enum["READONLY"] = 0] = "READONLY";
Enum[Enum["AUTHOR"] = 5] = "AUTHOR";
Enum["AUT"] = "Auto";
})(Enum || (Enum = {}));
;
if (Enum.READONLY === 0) {
console.log("Ok");
}
function combine(input, as) {
var result;
if (typeof input === 'number')
result = 5 * input;
else
result = 5 + input;
return result;
}
console.log(combine(4, "as-n"));
console.log(combine("4", 'as-n'));