title: Better sanity check for JavaScript variable
body: <p>So, I have a modular component... meaning it might appear in multiple applications. These are all internal, so the component's behaviour can "grow" as we add more products.</p>
  
  <p>Overall, there are probably better designs to accomplish what I want to accomplish, but in the interest of fast development, I was doing this:</p>
  
  <pre><code>function someFunc(opt) {
    if(typeof(taEnvironment) !== "undefined")) {
      if(taEnvironment === "webApp") {
        // do stuff when a variable taEnvironment exists and its value is "webapp"
      }
    }
  }
  </code></pre>
  
  <p>It's tedious to do this every time I need to check on "webApp", so I want to abstract it a LITTLE bit. The proposed refactor looks a bit like this:</p>
  
  <pre><code>function someFunc(opt) {
    if(environment("webApp")) {
        // do stuff when a variable taEnvironment exists and its value is "webapp"
    }
  }
  
  //...elsewhere in the same module...
  function environment(env) {
    var envSet = false;
    if(typeof(env) === "undefined") {
      return envSet;
    }
    if(typeof(taEnvironment) !== "undefined")) {
      if(taEnvironment === env) {
        envSet = true;
    }
    return envSet;
  }
  </code></pre>
  
  <p>2-part question:</p>
  
  <ol>
  <li><p>Even just looking at the first non-refactored snippet; is this the usual way to check for such variables? You can't combine the typeof check with a value check because if it's undefined you will get a failure on the value check. So first I check typeof for "undefined" and then nested inside, I check for the value. It SEEMS like the only way to do this, but if there's a better pattern, I'm all ears!</p></li>
  <li><p>Depending on the answer to #1 -- if #1 is a reasonable or expected way of doing things, does the proposed refactor make sense? Or am I not creating any significant efficiencies?</p></li>
  </ol>