Take the 2-minute tour ×

Possible Duplicate:

I've met "!==" strange comparison operator in source code of some chrome extension. Code snippet:

function closedTab(id) {
   if (openedTabs[id] !== undefined) {
      openedTabs[id].time = timeNow(0);

This operator is not used just once, so there's should some meaning.

Is "!==" came from some JavaScript magic? Or it's just equivalent to usual "!="? Thanks

share|improve this question
add comment

marked as duplicate by Greg Hewgill, AlienWebguy, Felix Kling, Donal Fellows, Graviton Aug 5 '11 at 15:56


5 Answers

up vote 4 down vote accepted

The difference is that !== doesn't try to convert its operands to the same type before comparing. Same with === and ==.

See this question: Difference between == and === in JavaScript

share|improve this answer
add comment

!== is the not identity comparison operator.

!= will coerce the two types to match

!== will not coerce the two types

For a few examples:

3 == "3"    // true - the operands are coerced to the same type, then compared and they match
3 === "3"   // false - the operands are not coerced to the same type, so do not match
3 != "3"    // false
3 !== "3"   // true
share|improve this answer
add comment

This is called a strict comparison operator where it not only checks for value but also for type.

share|improve this answer
add comment

The difference comes from what happens when values are of different type.

The !== operator (and its cousin ===) checks on the equality of both value and type. != and == on the other hand try to coerce values to be the same before checking equality.

For example:

if(5 === "5")      // evaluates to false
if(5 == "5")       // evaluates to true

The same concept is extended to != and !==

share|improve this answer
add comment

It's an identical comparison operator. It compares value and type. For example:

if('foobar' == true) // true
if('foobar' === true) // false
share|improve this answer
add comment
