-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_comparison_4.js
107 lines (91 loc) · 3.05 KB
/
js_comparison_4.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
function StringToNumber() {
console.log('\n\n- string => number');
console.log('Number("") :', Number(''));
console.log('Number("1") :', Number('1'));
console.log('Number("NaN") :', Number('NaN'));
console.log('Number("a1b2") :', Number('a1b2'));
}
function StringToBoolean() {
console.log('\n\n- string => boolean');
console.log('Boolean("") :', Boolean(''));
console.log('Boolean("0") :', Boolean('0'));
console.log('Boolean("true") :', Boolean('true'));
console.log('Boolean("false") :', Boolean('false'));
console.log('Boolean("a1b2") :', Boolean('a1b2'));
}
function NumberToString() {
console.log('\n\n- number => string');
console.log('String(1) :', String(1));
console.log('String(NaN) :', String(NaN));
}
function NumberToBoolean() {
console.log('\n\n- number => boolean');
console.log('Boolean(0) :', Boolean(0));
console.log('Boolean(NaN) :', Boolean(NaN));
console.log('Boolean(1) :', Boolean(1));
console.log('Boolean(2) :', Boolean(2));
}
function BooleanToString() {
console.log('\n\n- boolean => string');
console.log('String(true) :', String(true));
console.log('String(false) :', String(false));
}
function BooleanToNumber() {
console.log('\n\n- boolean => number');
console.log('Number(true) :', Number(true));
console.log('Number(false) :', Number(false));
}
function ArrayToString() {
console.log('\n\n- array => string');
console.log('String([]) :', String([]));
console.log('String([1]) :', String([1]));
console.log('String([1, 2]) :', String([1, 2]));
console.log('String(["a"]) :', String(['a']));
}
function ArrayToNumber() {
console.log('\n\n- array => number');
console.log('Number([]) :', Number([]));
console.log('Number([1]) :', Number([1]));
console.log('Number([1, 2]) :', Number([1, 2]));
console.log('Number(["a"]) :', Number(['a']));
}
function ArrayToBoolean() {
console.log('\n\n- array => boolean');
console.log('Boolean([]) :', Boolean([]));
console.log('Boolean([1]) :', Boolean([1]));
console.log('Boolean([1, 2]) :', Boolean([1, 2]));
console.log('Boolean(["a"]) :', Boolean(['a']));
}
function ObjectToString() {
console.log('\n\n- object => string');
console.log('String(null) :', String(null));
console.log('String(undefined) :', String(undefined));
console.log('String({}) :', String({}));
console.log('String({ a: 1 }) :', String({ a: 1 }));
}
function ObjectToNumber() {
console.log('\n\n- object => number');
console.log('Number(null) :', Number(null));
console.log('Number(undefined) :', Number(undefined));
console.log('Number({}) :', Number({}));
console.log('Number({ a: 1 }) :', Number({ a: 1 }));
}
function ObjectToBoolean() {
console.log('\n\n- object => boolean');
console.log('Boolean(null) :', Boolean(null));
console.log('Boolean(undefined) :', Boolean(undefined));
console.log('Boolean({}) :', Boolean({}));
console.log('Boolean({ a: 1 }) :', Boolean({ a: 1 }));
}
StringToNumber();
StringToBoolean();
NumberToString();
NumberToBoolean();
BooleanToString();
BooleanToNumber();
ArrayToString();
ArrayToNumber();
ArrayToBoolean();
ObjectToString();
ObjectToNumber();
ObjectToBoolean();