0

Possible Duplicates:
Is there a difference between !== and != in PHP?
Javascript === vs == : Does it matter which “equal” operator I use?

In some cases when checking for not equal, I saw using != and in some places i saw !==. Is there any difference in that?

Example:

var x = 10;   

if (x != 10) {   
    //...
}

and

if (x !== 10) {    
    //...
}
Community
  • 1
  • 1
Kanishka Panamaldeniya
  • 16,732
  • 29
  • 117
  • 190

6 Answers6

7

== compares only the value and converts between types to find an equality, === compares the types as well.

Femaref
  • 59,667
  • 7
  • 131
  • 173
3
  • == means equal
  • === means identical

1 is equal to "1", but not identical, because 1 is an integer and "1" is a string.

rid
  • 57,636
  • 30
  • 143
  • 185
3

They are different in terms of strictness of comparison. !== compares variable types in addition to values.

Emre Yazici
  • 9,946
  • 6
  • 47
  • 54
2

!== will also check the type (int, string, etc.) while != doesn't.

For more information, see the PHP comparison operator documentation.

Francois Deschenes
  • 24,403
  • 4
  • 62
  • 59
2

The !== is strict not equal: Difference between == and === in JavaScript

Community
  • 1
  • 1
Mark PM
  • 2,869
  • 12
  • 18
2

The difference is that == (and !=) compare only the value, === (and !==) compare the value and the type.

For example
"1" == 1 returns true
"1" === 1 returns false, because one is a string and the other is an integer

Hope this helps. Cheers

Edgar Villegas Alvarado
  • 17,924
  • 2
  • 41
  • 61