Monday, February 3, 2014

JavaScript: Special Comparison Operators

== vs ===

One thing common in both the cases is that they are comparison operator to check equality.

The only difference is '===' will match for both value and type.

Example:

1===1 returns true
1==="1" returns false (Number compared against String)
But 1=="1" returns true

!= vs !==

One thing common in both the cases is that they are comparison operator to check inequality.

The only difference is '!==' will match for both value and type.

Example:
 

1!==1 returns false
1!=="1" returns true (Number compared against String)
But 1!="1" returns false

No comments:

Post a Comment

Please leave your comments here...