Difference between double equals and triple equals

What is the difference between == and ===? How double equals differs from triple equals?

strong equality javascript

They are both checking the equality. Double equals does not care about data type. Triple equals does care about data types.

We can say that double equls checks equality but triple equals check strong equality.

"0" == 0
is true
"0" === 0
is false because string does not equals to number
Also one more weird thing. Javascript thinks empty string equals zero. When checking strong equality with triple equals it is false.
" " == 0
is true because Javascript consides empty string as zero
" " === 0
is false
Please remember about that writing code. Use triple equals where possible to avoid bugs.

Leave a Reply

Your email address will not be published.