Skip to content

Commit 873fae9

Browse files
feat: add value comparison operators
1 parent bfcf80f commit 873fae9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
INFO: == (Equality - Loose Equality)
3+
Checks if two values are equal after type coercion (i.e., javascript will try to convert the values to the same type before comparing)
4+
*/
5+
console.log(5 == "5"); // true (string '5' is coerced to number 5)
6+
console.log(null == undefined); // true
7+
console.log(0 == false); // true
8+
9+
/*
10+
INFO: === (Strict Equality)
11+
Compares both value and type
12+
No type coercion - values must be the same type and value to be true
13+
*/
14+
console.log(5 === "5"); // false
15+
console.log(5 === 5); // true
16+
console.log(null === undefined); // false
17+
console.log(0 === false); // false
18+
19+
/*
20+
INFO: Object.is() (SameValue comparison)
21+
Similar to ===, but with two key differences:
22+
*/
23+
console.log(Object.is(5, 5)); // true
24+
console.log(Object.is("5", 5)); // false
25+
console.log(Object.is(NaN, NaN)); // true
26+
console.log(Object.is(+0, -0)); // false

0 commit comments

Comments
 (0)