DEV Community

Vamshi Krishna
Vamshi Krishna

Posted on

What is the difference between == and === operators

The "==" operator compares values for equality, after doing any necessary type conversions.
The "===" operator, on the other hand, compares both value and type, and will only return true if the value and type match. In general, it is recommended to use the "===" operator, as it is less prone to unexpected behavior caused by type coercion.

For Example :
0 == false // true
0 === false // false
1 == "1" // true
1 === "1" // false
null == undefined // true
null === undefined // false
'0' == false // true
'0' === false // false
[]==[] or []===[] //false, refer different objects in memory
{}=={} or {}==={} //false, refer different objects in memory

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay