title: When JavaScript returns null & undefined?
body: <p>I have been using JavaScript for couple of years and never cared about the difference between <code>null</code> &amp; <code>undefined</code> earlier, I always use <code>undefined</code> to validate the object existence.</p>
  
  <p>But recently I came through <a href="https://developer.mozilla.org/en/A_re-introduction_to_JavaScript" rel="noreferrer">this article</a>. Here they said</p>
  
  <blockquote>
    <p>JavaScript distinguishes between null, which is an object of type 'object' that indicates a deliberate non-value, and undefined, which is an object of type 'undefined' that indicates an uninitialized value — that is, a value hasn't even been assigned yet. We'll talk about variables later, but in JavaScript it is possible to declare a variable without assigning a value to it. If you do this, the variable's type is undefined.</p>
  </blockquote>
  
  <p>I am completely confused now, what exactly is non-value here. How this non-value differs from <code>undefined</code>. And what are the circumstances javascript returns <code>null</code>.</p>
  
  <p>I have tried the below sample </p>
  
  <pre><code>var sam;
  alert(sam);  // returns undefined
  </code></pre>
  
  <p>And</p>
  
  <pre><code>try {
      //var sam;
      alert(sam);  
  } catch(ex) { }   // exception says: sam is undefined
  </code></pre>
  
  <p>And I am not sure about when js returning nulls. Can someone clarify me.</p>