Should I use (typeof(val) === 'undefined') or (val === undefined)?
<p>This is similar to a number of other questions on SO, but not exactly the same as any I can find.</p>

<p>Which is the best approach for checking for an undefined value in Javascript, and why? </p>

<p>First example:</p>

<pre><code>var a;
if (typeof(a) === 'undefined'){...}
</code></pre>

<p>Second example:</p>

<pre><code>var a;
if (a === undefined){...}
</code></pre>

<p>So, the first example is comparing the name of the type to a string, and the second is comparing the variable to the undefined object, using the equality operator, which checks that the types are the same as well as the values.</p>

<p>Which is better?  Or are they both as good as one another?</p>

<p>Note that I'm not asking about any difference between undefined and null, or truthy or falsey, just which of these two methods is correct and/or better.</p>
