Difference between == and === in JavaScript [duplicate] Difference between == and === in JavaScript [duplicate] javascript javascript

Difference between == and === in JavaScript [duplicate]


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   // true0 === false  // false, because they are of a different type1 == "1"     // true, automatic type conversion for value only1 === "1"    // false, because they are of a different typenull == undefined // truenull === undefined // false'0' == false // true'0' === false // false


=== and !== are strict comparison operators:

JavaScript has both strict andtype-converting equality comparison.For strict equality the objects beingcompared must have the same type and:

  • Two strings are strictly equal when they have the same sequence ofcharacters, same length, and samecharacters in corresponding positions.
  • Two numbers are strictly equal when they are numerically equal (havethe same number value). NaN is notequal to anything, including NaN.Positive and negative zeros are equalto one another.
  • Two Boolean operands are strictly equal if both are true orboth are false.
  • Two objects are strictly equal if they refer to the same Object.
  • Null and Undefined types are == (but not ===). [I.e. (Null==Undefined) is true but (Null===Undefined) is false]

Comparison Operators - MDC