javascript / beginner
Snippet
Strict vs. Loose Equality
Loose equality (==) performs type coercion, meaning it converts values to a common type before comparing. Strict equality (===) checks both value and data type without conversion.
snippet.js
1
2
console.log(5 == "5"); // true (Loose)console.log(5 === "5"); // false (Strict)
nodejs
Breakdown
1
5 == "5"
Returns true because the string '5' is coerced into the number 5.
2
5 === "5"
Returns false because number and string are different types.