Javascript Operators === & !==
The actual difference between Javascript's == and === operators is that the == operator is less strict when comparing the operands. For example, 1=="1" evaluates to true while 1==="1" evaluates to false.Full description can be found on ECMAScript standard, at...
The actual difference between Javascript's
==
and ===
operators is that the ==
operator is less strict when comparing the operands. For example, 1=="1"
evaluates to true
while 1==="1"
evaluates to false
.
Full description can be found on ECMAScript standard, at http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf, on chapter 11.9.
A practical tip to quickly understand "what would ==
do" is to illustrate what will happen when you call .toString()
on both operands. Thinking that way, it will make sense that 1.toString()=="1"
. This is not the precise algorithm for ==
, but it does provide a good approximation, useful for daily work.