title: Javascript undefined, empty strings, and if statements
body: <p>I am not some one who has done alot in javascript. My background is in Java/C++. I am currently working on a project that is using alot of javascript however and I came across something that doesn't make sense to me but hopefully some javascript guru out there can give me a nice logical explanation.</p>
  
  <pre><code>var noDefinition = undefined;
  var emptyString = "";
  var noDefinitionAndEmptyString = noDefinition + emptyString;
  
  console.log("NoDefinition");
  console.log(noDefinition);
  
  console.log("EmptyString");
  console.log(emptyString);
  
  console.log("noDefinition+emptyString");
  console.log(noDefinitionAndEmptyString);
  
  console.log("************************");
  if(noDefinition == undefined)
  {
      console.log("No Definition is undefined");
  }
  
  
  if(emptyString == undefined)
  {
      console.log("emptyString is undefined");
  }
  
  if(noDefinitionAndEmptyString == undefined)
  {
      console.log("noDefiniton and emptyString is undefined");
  }
  </code></pre>
  
  <p>The code above produces the following results in my console:<br />
   [INFO] NoDefinition <br />
   [INFO] <br />
   [INFO] EmptyString <br />
   [INFO] <br />
   [INFO] noDefinition+emptyString<br />
   [INFO] undefined<br />
   [INFO] <strong><em>*</em>**<em>*</em>**<em>*</em>**<em>*</em>**</strong><br />
   [INFO] No Definition is undefined<br /></p>
  
  <p>So as you can see when I output the variables noDefinition and emptyString to the console, it produces blank output. When I concatenate them the console will produce undefined. However if I then proceed to use an if statement and compare each of them to undefined. The only if that executes is the first one. </p>
  
  <p>This occurs even though when put to a console the value just shows up blank. Also     the concatenation which shows up as undefined in the console fails its compare against undefined and never executes.  I am confused by this and I am hoping out there some one can give me an explanation about what is going on.</p>