title: Javascript using if(foo) exists to check if variable is set
body: <p>I realize that this question is extremely similar to many others, but I must be missing some nuance with checking whether a variable is set or not. I have seen this in other developers code:</p>
  
  <pre><code>if(foo){
    doSomething(foo);
  }
  else{
    alert('error of whatever');
  }
  </code></pre>
  
  <p>With the intent that the doSomething() will only execute if foo is set or not undefined. However, when I google this, it seems everyone says "typeof" should be used instead of the above method. I specifically see this in use with angular, like this:</p>
  
  <pre><code>if($scope.property){
    dothis();
  }
  </code></pre>
  
  <p>Am I missing something? When I see the above code, it seems to work, but all the answers I see never say this is the correct way to check if something is set or exists. </p>