title: Why does an undefined variable in Javascript sometimes evaluate to false and sometimes throw an uncaught ReferenceError?
body: <p>Everything I've ever read indicates that in Javascript, the boolean value of an undefined variable is False. I've used code like this hundreds of times:</p>
  
  <pre><code>if (!elem) {
     ...
  }
  </code></pre>
  
  <p>with the intent that if "elem" is undefined, the code in the block will execute. It usually works, but on occasion the browser will throw an error complaining about the undefined reference. This seems so basic, but I can't find the answer. </p>
  
  <p>Is it that there's a difference between a variable that has not been defined and one that has been defined but which has a value of undefined? That seems completely unintuitive.</p>