Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / HTML

Javascript Operators === & !==

3.67/5 (3 votes)
11 Mar 2011CPOL 18.6K  
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)