- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript == vs ===
JavaScript Type System
JavaScript == vs ===
The double equals converts types before comparing; the triple equals does not.
This is one of the most asked JavaScript interview questions.
The short advice is simple: use === unless you have a reason not to.
Example
Example
javascript
console.log("5" == 5);
console.log("5" === 5);The output is true then false.
== converted the string; === compared the types too.
Loose and Strict Equality
== is loose equality: it converts types, then compares.
=== is strict equality: different types are never equal.
