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
  • 17,302
  • 31
  • 123
  • 193

6 Answers6

7

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

Femaref
  • 60,705
  • 7
  • 138
  • 176
3
  • == means equal
  • === means identical

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

rid
  • 61,078
  • 31
  • 152
  • 193
3

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

Emre Yazici
  • 10,136
  • 6
  • 48
  • 55
2

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

For more information, see the PHP comparison operator documentation.

Francois Deschenes
  • 24,816
  • 4
  • 64
  • 61
2

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

Community
  • 1
  • 1
Mark PM
  • 2,909
  • 14
  • 19
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
  • 18,204
  • 2
  • 42
  • 61