Click here to Skip to main content
11,578,739 members (61,443 online)
Click here to Skip to main content

Javascript Operators === & !==

, 10 Mar 2011 CPOL 4.8K 1
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 ?

You may also be interested in...

Comments and Discussions

 
GeneralRe: there is nothing called [give a javascript developer a quick... Pin
Antoun Gorgy10-Mar-11 20:31
memberAntoun Gorgy10-Mar-11 20:31 
Generalthere is nothing called [give a javascript developer a quick... Pin
Antoun Gorgy10-Mar-11 20:33
memberAntoun Gorgy10-Mar-11 20:33 
GeneralReason for my vote of 1 inaccurate and not precise algorithm Pin
Antoun Gorgy10-Mar-11 9:23
memberAntoun Gorgy10-Mar-11 9:23 
GeneralRe: dude - are you for real? I clearly stated this in the tip - ... Pin
egozi1310-Mar-11 9:28
memberegozi1310-Mar-11 9:28 
GeneralAllright guys. I've updated my tip to state clearly that it ... Pin
egozi1310-Mar-11 1:15
memberegozi1310-Mar-11 1:15 
GeneralCopying from the ECMAscript standard is hardly a "tip". If a... Pin
egozi139-Mar-11 7:48
memberegozi139-Mar-11 7:48 
GeneralRe: here u are; a link from the ECMA http://www.ecma-internation... Pin
Antoun Gorgy9-Mar-11 8:07
memberAntoun Gorgy9-Mar-11 8:07 
Generalactually when you read section 11.9.3 in his comment it will... Pin
Antoun Gorgy9-Mar-11 4:39
memberAntoun Gorgy9-Mar-11 4:39 
GeneralØyvind - I don't see how your algorithm explain the result t... Pin
egozi138-Mar-11 7:55
memberegozi138-Mar-11 7:55 
General@egozi13: See my alternate. Your alternate should quite fran... Pin
Øyvind Sean Kinsey7-Mar-11 23:42
memberØyvind Sean Kinsey7-Mar-11 23:42 
GeneralI was not familiar with the 'alternate' option, I thought I ... Pin
egozi131-Mar-11 0:40
memberegozi131-Mar-11 0:40 
Generalwhere is the alternate :) Pin
Antoun Gorgy28-Feb-11 21:17
memberAntoun Gorgy28-Feb-11 21: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
Web03 | 2.8.150603.1 | Last Updated 11 Mar 2011
Article Copyright 2011 by egozi13
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid