2

Possible Duplicate:
JavaScript === vs == : Does it matter which “equal” operator I use?
Javascript operator !==

What's the difference between != and !==?

Can you give me an example where using != gives another result than using !==?

Community
  • 1
  • 1
Alexandre Khoury
  • 3,896
  • 5
  • 37
  • 58
  • 2
    http://stackoverflow.com/questions/6559358/what-is-the-difference-between-and?rq=1 should help – 4444 Aug 14 '12 at 20:57

1 Answers1

8
alert(1 != true);
alert(1 !== true);

The first one is false, the second true.

  • != accept 1 as equals of true, null as equals of false and some others (because the values are automatically casted when being compared).
  • !== accept only "real" equalities (i.e. compares both the value and the type).

Example

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Diego
  • 16,436
  • 26
  • 84
  • 136