LanguagesJavaScriptDouble vs. Single Equal Sign

Double vs. Single Equal Sign content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

JavaScript tutorial

Let’s tear this one apart. Today we are going to look at a rather small but quite important command in most high-level programming languages, such as Python, Java, and C# – the equal sign or =.

Let’s take a quick look at the following JavaScript:

<SCRIPT LANGUAGE="javascript">
<!--Hide the Script
//This Script written by Joe Burns, Ph.D. 
//Use it freely
if (navigator.appname == "Internet Exploder")



// End hiding the Script--> 

I want you to look at two uses of the equal sign within the script:

(navigator.appname == "Internet Exploder") 



Notice the first use of the equal sign doubles it up and the second is the more traditional single equal sign. Now, to us humans, one or two equal signs do not make for a big difference, but to a JavaScript-reading computer, it signifies a great deal of difference.

Without getting into a lot of programming mumbo jumbo, here’s the basic difference (and this always did seem backward to me).

  • A double equal sign means “is equal to.
    Notice the line above involving the double equal sign? It is saying if the navigator application name is equal to Internet Exploder.
  • A single equal sign means “is.
    I’m sure there’s a better way of putting it, but that’s how I keep it all straight. Notice the line above that uses the single equal sign? It is saying the parent location is nspage.html.

You will also see a single equal sign being used to denote variables and the like. Just keep it all straight by remembering that only the double equal sign means “is equal to” and the single equal sign can be roughly translated into “is.”

That should help you keep it all straight, too.

Read more programming tutorials and developer tool reviews.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories