Click here to Skip to main content
15,881,757 members
Articles / Web Development / HTML
Alternative
Tip/Trick

Javascript Operators === & !==

Rate me:
Please Sign up or sign in to vote.
3.67/5 (3 votes)
10 Mar 2011CPOL 16.8K   1   12
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)


Written By
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... Pin
AntounPG10-Mar-11 20:31
AntounPG10-Mar-11 20:31 
Generalthere is nothing called [give a javascript developer a quick... Pin
AntounPG10-Mar-11 20:33
AntounPG10-Mar-11 20:33 
GeneralReason for my vote of 1 inaccurate and not precise algorithm Pin
AntounPG10-Mar-11 9:23
AntounPG10-Mar-11 9:23 
GeneralRe: dude - are you for real? I clearly stated this in the tip - ... Pin
egozi1310-Mar-11 9:28
egozi1310-Mar-11 9:28 
GeneralAllright guys. I've updated my tip to state clearly that it ... Pin
egozi1310-Mar-11 1:15
egozi1310-Mar-11 1:15 
Allright guys. I've updated my tip to state clearly that it is not the precise algorithm, but a good and useful approximation (what I call a tip)
GeneralCopying from the ECMAscript standard is hardly a "tip". If a... Pin
egozi139-Mar-11 7:48
egozi139-Mar-11 7:48 
GeneralRe: here u are; a link from the ECMA http://www.ecma-internation... Pin
AntounPG9-Mar-11 8:07
AntounPG9-Mar-11 8:07 
Generalactually when you read section 11.9.3 in his comment it will... Pin
AntounPG9-Mar-11 4:39
AntounPG9-Mar-11 4:39 
GeneralØyvind - I don't see how your algorithm explain the result t... Pin
egozi138-Mar-11 7:55
egozi138-Mar-11 7:55 
General@egozi13: See my alternate. Your alternate should quite fran... Pin
Øyvind Sean Kinsey7-Mar-11 23:42
Øyvind Sean Kinsey7-Mar-11 23:42 
GeneralI was not familiar with the 'alternate' option, I thought I ... Pin
egozi131-Mar-11 0:40
egozi131-Mar-11 0:40 
Generalwhere is the alternate :) Pin
AntounPG28-Feb-11 21:17
AntounPG28-Feb-11 21:17 

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

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