46

Possible Duplicate:
Javascript === vs ==

What's the diff between "===" and "==" ? Thanks!

Community
  • 1
  • 1

5 Answers5

61

'===' means equality without type coersion. In other words, if using the triple equals, the values must be equal in type as well.

e.g.

0==false   // true
0===false  // false, because they are of a different type
1=="1"     // true, auto type coersion
1==="1"    // false, because they are of a different type

Source: http://longgoldenears.blogspot.com/2007/09/triple-equals-in-javascript.html

glasnt
  • 2,865
  • 5
  • 35
  • 55
16

Ripped from my blog: keithdonegan.com

The Equality Operator (==)

The equality operator (==) checks whether two operands are the same and returns true if they are the same and false if they are different.

The Identity Operator (===)

The identity operator checks whether two operands are “identical”.

These rules determine whether two values are identical:

  • They have to have the same type.
  • If number values have the same value they are identical, unless one or both are NaN.
  • If string values have the same value they are identical, unless the strings differ in length or content.
  • If both values refer to the same object, array or function they are identical.
  • If both values are null or undefined they are identical.
Keith Donegan
  • 26,213
  • 34
  • 94
  • 129
8

The === operator means "is exactly equal to," matching by both value and data type.

The == operator means "is equal to," matching by value only.

Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
3

It tests exact equality of both value and type.

given the assignment
x = 7

x===7 is true
x==="7" is false
Larsenal
  • 49,878
  • 43
  • 152
  • 220
2

In a nutshell "===" tests for the equality of value AND of type: From here:

chiggsy
  • 8,153
  • 5
  • 33
  • 43