65.9K
CodeProject is changing. Read more.
Home

Javascript Operators === & !==

starIconstarIconstarIcon
emptyStarIcon
starIcon
emptyStarIcon

3.67/5 (3 votes)

Mar 1, 2011

CPOL
viewsIcon

18644

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.