Repository navigation
Expand file tree
/
Copy pathdatatypes.js
More file actions
86 lines (69 loc) · 1.73 KB
/
Copy pathdatatypes.js
File metadata and controls
86 lines (69 loc) · 1.73 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
function show(x) { console.log(x) }
function line(x) { console.log(`line ${x} --> `) }
//8 Data Types
//-------------------------------------------
//1 - number
// some special number NaN , Infinity , -Infinity
show(typeof (Infinity));
show(`line 9 --> ${typeof (NaN)}`);
// 2. NaN represent a computational error
show("string" / 3);
// NaN is sticky
show("string" / 2 + 5 - 8);
//or
show(2 + 3 / "String")
//------------------------------
// bigint --- number is limited to 2^53
// made by adding 'n' at last of a number
show(`line 22 --> ${typeof (134567890n)}`)
// 3. String
let str1 = "can be written in double Quote"
let str2 = 'also can be written in single quote'
//backticks can use expression and variable too
let something = "backticks"
let str = `in ${something} also`
show(str)
// 4. boolean - true / false value only
let isBun = true;
line(36)
show(typeof (isBun))
let isNPM = false;
show(typeof isNPM)
// also come as result of comparison
line(43)
show(5 < 3);
// 5. Null
// A value purposely or implicitely set empty , Nothing
// or unknown
let value = null;
line(50)
show(typeof value) // wrong in js it is actually null
// 6. undefined
// meaning value is not set/assigned
let aVar;
line(56)
show(aVar)
// undefined can be value also
let var2 = undefined;
line(61);
show(var2)
// But null is preferred not undefined
let var23 = null;
line(67)
show(var23)
///// ---- typeof operator
// typeof operator returns va;lue as string
//used in 2 form
// typeof value
// typeof (value)
// only works with a operand
line(77)
show(typeof undefined);
show(typeof (2345678));
show(typeof 3456789n);
show(typeof true);
show(typeof "foo");
show(typeof Symbol("id"));
show(typeof Math);
show(typeof null);//wrong in js
show(typeof alert);