开发者

what is the difference between '!= 'and '!== ' [duplicate]

This question already has answers here: Closed 11 years ago.

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) {   
    //..开发者_如何学Python.
}

and

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


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


  • == means equal
  • === means identical

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


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


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

For more information, see the PHP comparison operator documentation.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜