-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path004-Typeof-and-DataTypes.js
67 lines (50 loc) · 1.63 KB
/
004-Typeof-and-DataTypes.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
65
66
67
/*
* Author : Jaydatt Patel
Data types and Typeof function
*/
var obj = typeof "Hello";
console.log('"Hello" :', obj);
var obj = typeof 'Hello"s world';
console.log("'Hello\"s world':", obj);
var obj = typeof `"Hello's world"`;
console.log('`"Hello\'s world"` :', obj);
obj = typeof 10;
console.log("10 :", obj);
obj = typeof 10n;
console.log("10n:", obj);
obj = typeof 3.14;
console.log("3.14 :", obj);
obj = typeof true;
console.log("true :", obj);
obj = typeof (1 <= 2);
console.log("(1<=2) :", obj);
obj = typeof [1, 2, 3];
console.log("[1,2,3] :", obj);
obj = typeof { city: "Ahme" };
console.log("{ city : 'Ahme'} :", obj);
var obj = typeof null;
console.log("NULL:", obj);
var obj = typeof var_undefine;
console.log("var_undefine :", obj);
obj = typeof function sum(a, b) {
return a + b;
};
console.log("function sum(a,b) {return(a+b)} :", obj);
obj = typeof new Date(); //=== "object";
console.log("(new Date()) :", obj);
obj = typeof /regex/; //=== "object";
console.log("/regex/ :", obj);
// The following are confusing, dangerous, and wasteful. Avoid them.
obj = typeof new Boolean(true); //=== "object";
console.log("(new Boolean(true)) :", obj);
obj = typeof new Number(1); //=== "object";
console.log("(new Number(1)) :", obj);
obj = typeof new String("abc"); //=== "object";
console.log('(new String("abc"):', obj);
// Functions
obj = typeof function () {}; //=== "function";
console.log("function () {} :", obj);
obj = typeof class C {}; //=== "function";
console.log("class C {} :", obj);
obj = typeof Math.sin; //=== "function";
console.log("Math.sin :", obj);