Javascript equality(==) and identity(===) operators

0

The identity operator(===) compares the type and value of the operands , while the equality operator(==) compares just the values .

So , given var i=1

i=='1' will return true , while i==='1' will return false .

Quote from  Javascript : The good parts


JavaScript has two sets of equality operators: === and !==, and their evil twins == and !=. The good ones work the way you would expect. If the two operands are of the same type and have the same value, then === produces true and !== produces false. The evil twins do the right thing when the operands are of the same type, but if they are of different types, they attempt to coerce the values. the rules by which they do that are complicated and unmemorable. 
My advice is to never use the evil twins. Instead, always use === and !==.

Read more »

0 comments:

Post a Comment

© Zone817. Powered by Blogger.