JavaScript : Check if variable exists and if equal to value
<p>I have three pages utilizing the same code and on one of the pages this variable doesn't exist, on the other two the variable ticketType has a value of 1 or 2.  I need to first check if ticketType exists and isn't undefined and secondly, need to determine if it's one or 2.</p>

<p>This if statement generates an error:</p>

<pre><code>if(typeof ticketType != undefined &amp;&amp; ticketType == 1){}
</code></pre>

<p>It's saying <code>ticketType isn't defined</code>.  I tried nesting the if statements to check if it was defined first thinking it wouldn't go and try the inner if statement but firebug still generates an error.</p>

<p>Any ideas?  There has to be a way to do this...</p>
