Javascript: Best way to check value of variable which might be undefined
<p>I need to check if thevar[2] === 'debug' however thevar[2] might be undefined so if I ran the following code with it being undefined javascript would throw an error:</p>

<pre><code>if (thevar[2] === 'debug') {
  console.log('yes');
}
</code></pre>

<p>So what I'm currently doing is:</p>

<pre><code>  if (typeof thevar[2] !== 'undefined') {
    if (thevar[2] === 'debug') {
      console.log('yes');
    }
  }
</code></pre>

<p>Is this really the best way to do this?</p>
