What is the difference between == and === in JavaScript?
== (loose equality) converts the types before comparing. === (strict equality) compares the value and the type.
console.log(5 == "5");
console.log(5 === "5");
console.log(0 == false);
console.log(0 === false);
console.log(null == undefined);
console.log(null === undefined);
Output:
Tutorials Class - Output Window
true
false
true
false
true
false
Use === and !== to avoid surprising results. See Type Conversion.
Learn more about the similar topics:
| Tutorials |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |