Skip to content

Commit 3d7e0cc

Browse files
committed
Strict Equality Comparison
1 parent 83807cb commit 3d7e0cc

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ Primitive Types, Non-Primitive Types, `typeof` operatior, Special values like Na
99
Abstract Operations: ToPrimitive, ToString, ToNumber and ToBoolean
1010

1111
## [Abstract Equality Comparison vs Strict Equality Comparison](abstract-equality-vs-strict-equality/README.md)
12+
13+
Abstract Equality Comparison, Strict Equality Comparison, Corner cases of Abstract Equality Comparison.

abstract-equality-vs-strict-equality/README.md

+54
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,58 @@ If only if Type(x) and Type(y) does not matches, Abstract Equality Comparison al
2828

2929
- If Type(x) is Object and Type(y) is either String or Number, return the result of the comparison ToPrimitive(x) == y.
3030

31+
## Corner cases
32+
33+
<!-- prettier-ignore -->
34+
```js
35+
42 == [42] // true
36+
37+
42 == "42"
38+
42 == 42
39+
```
40+
41+
<!-- prettier-ignore -->
42+
```js
43+
[] == ![] // true
44+
45+
// [] is truthy value so it evaluates to true and !true is false
46+
[] == false
47+
// because one value is non-ptimitive ToPrimitive will be applied
48+
"" == false
49+
// Abstract equality conversion prefer ToNumber
50+
0 == 0
51+
```
52+
53+
<!-- prettier-ignore -->
54+
```js
55+
var students = [] // true
56+
57+
// This is correct way of checking..
58+
if(students) {
59+
// Yep
60+
}
61+
62+
// [] == true
63+
// "" == true
64+
// 0 == 1
65+
if(students == true) {
66+
// Nope
67+
}
68+
69+
// [] == false
70+
// "" == false
71+
// 0 == 0
72+
if(students == false) {
73+
// Yep
74+
}
75+
```
76+
3177
## Strict Equality Comparison
78+
79+
Strict Equality Comparison return false if the types different for x and y.
80+
81+
- undefined === undefined return true
82+
- null === null return true
83+
- NaN === NaN return false
84+
- +0 === -0 return true
85+
- -0 === 0 return true

0 commit comments

Comments
 (0)