Monday, February 1, 2016

What is the differebce between using == and === ?


The == or != operator perform an automatic type conversion in Javascript if you want to compare between two values like this '10' == 10 , for this example we already know that 10 is number but '10' is not number it is string but when we compare that values one of them will convert to the same datatype we can say maybe '10' convert to number before compare, anyway we don't recommend to use this.
The === or !== operator will not perform any conversion mean it compares both value and datatype which could be faster than using == operator.
Example:[10] === 10 // is false[10] == 10 // is true'10' == 10 // is true'10' === 10 // is false [] == 0 // is true [] === 0 // is false '' == false // is true but true == "a" is false '' === false // is false



0 comments:

Post a Comment