File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
part1 (Basics)/value-comparison-operators Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments