-
Notifications
You must be signed in to change notification settings - Fork 0
/
equals operator.js
74 lines (49 loc) · 1.33 KB
/
equals operator.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
// == vs. ===
// == -> smart one (compares values)
// === -> strict one (compares value and type)
console.log(2 == '2'); // -> true !!!!
console.log(2 === '2'); // -> false
// __Equality for various types____________
// 1. numbers
console.log(2 == 2); // -> true
console.log(2 === 2); // -> true
console.log(2 == 2.0); // -> true
console.log(2 === 2.0); // -> true
// 2. strings
console.log('' == ''); // -> true
console.log('' === ''); // -> true
console.log('abc' == 'abc'); // -> true
console.log('abc' === 'abc'); // -> true
let s1, s2;
s1 = 'abc';
s2 = 'abc';
console.log(s1 == s2); // -> true
console.log(s1 === s2); // -> true
s1 = 'abc';
s2 = s1;
console.log(s1 == s2); // -> true
console.log(s1 === s2); // -> true
// 3. arrays
console.log([1, 2, 3] == [1 , 2, 3]); // -> false
console.log([1 , 2, 3] === [1 , 2, 3]); // -> false
let a1, a2;
a1 = [1, 2, 3];
a2 = [1, 2, 3];
console.log(a1 == a2); // -> false
console.log(a1 === a2); // -> false
a1 = [1, 2, 3];
a2 = a1;
console.log(a1 == a2); // -> true
console.log(a1 === a2); // -> true
// 4. objects
console.log({} == {}); // -> false
console.log({} === {}); // -> false
let ob1, ob2;
ob1 = {};
ob2 = {};
console.log(ob1 == ob2); // -> false
console.log(ob1 === ob2); // -> false
ob1 = {};
ob2 = ob1;
console.log(ob1 == ob2); // -> true
console.log(ob1 === ob2); // -> true