Careeroza
Comparison & Equality
== vs ===
Example
=== (strict equality) compares value and type. == converts types first, which causes surprises:
console.log(5 === 5, 5 === "5");
console.log(5 == "5");
console.log(0 == false, "" == 0);
console.log(null == undefined, null === undefined);
console.log(NaN === NaN, Number.isNaN(NaN));Output
true false true true true true false false true
Note: Always use === and !==. The only common exception: x == null checks for both null and undefined.
Relational Operators
Example
Strings compare alphabetically, character by character (by Unicode value):
console.log(10 > 9);
console.log("10" > "9"); // string comparison: "1" < "9"
console.log("apple" < "banana");
console.log("Zebra" < "apple"); // uppercase letters come firstOutput
true false true true