Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Javascript Operators === & !==

, 11 Mar 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

egozi13
Web Developer
Israel Israel
Currently a .NET Team Leader at a mid-sized software company, I've started coding at the age of 5, using BASIC on a ZX-Spectrum 48 computer.
Gradually i've moved up the generations, from ZX assembly language, through c and Pascal, I've became an IS programmer on VB6 and SQL-Server, eventually upscaling to c#, and doing OOD stuff for a living.
 
I'm about to get my Bachelor's degree in Computer Science this semester, and looking forward to go on with M.Sc. in the area of Algorithmics.
 
So I work in Information Systems, and my hobby is "learning and developing algorithms". Can you get more geeky than that ?

Comments and Discussions

 
GeneralRe: there is nothing called [give a javascript developer a quick... PinmemberAntoun Gorgy10-Mar-11 21:31 
Generalthere is nothing called [give a javascript developer a quick... PinmemberAntoun Gorgy10-Mar-11 21:33 
GeneralReason for my vote of 1 inaccurate and not precise algorithm PinmemberAntoun Gorgy10-Mar-11 10:23 
GeneralRe: dude - are you for real? I clearly stated this in the tip - ... Pinmemberegozi1310-Mar-11 10:28 
GeneralAllright guys. I've updated my tip to state clearly that it ... Pinmemberegozi1310-Mar-11 2:15 
GeneralCopying from the ECMAscript standard is hardly a "tip". If a... Pinmemberegozi139-Mar-11 8:48 
GeneralRe: here u are; a link from the ECMA http://www.ecma-internation... PinmemberAntoun Gorgy9-Mar-11 9:07 
Generalactually when you read section 11.9.3 in his comment it will... PinmemberAntoun Gorgy9-Mar-11 5:39 
GeneralØyvind - I don't see how your algorithm explain the result t... Pinmemberegozi138-Mar-11 8:55 
General@egozi13: See my alternate. Your alternate should quite fran... PinmemberØyvind Sean Kinsey8-Mar-11 0:42 
GeneralI was not familiar with the 'alternate' option, I thought I ... Pinmemberegozi131-Mar-11 1:40 
Generalwhere is the alternate :) PinmemberAntoun Gorgy28-Feb-11 22:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 11 Mar 2011
Article Copyright 2011 by egozi13
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid