Difference between == and === in JavaScript

Shiva picture Shiva · Feb 7, 2009 · Viewed 991.7k times · Source

What is the difference between == and === in JavaScript? I have also seen != and !== operators. Are there more such operators?

Answer

sdfx picture sdfx · Feb 7, 2009

Take a look here: http://longgoldenears.blogspot.com/2007/09/triple-equals-in-javascript.html

The 3 equal signs mean "equality without type coercion". Using the triple equals, the values must be equal in type as well.

0 == false   // true
0 === false  // false, because they are of a different type
1 == "1"     // true, automatic type conversion for value only
1 === "1"    // false, because they are of a different type
null == undefined // true
null === undefined // false
'0' == false // true
'0' === false // false