Is it wrong to declare a variable inside an if statement in Javascript?
<p>I have a Sublimelinter installed in Sublime Text 2 and it's great. However it doesn't like the following code:</p>

<pre><code>if(condition){
    var result = 1;
}else{
    var result = 2;
}
process(result);
</code></pre>

<p>It says for <code>var result = 2;</code> that result is already defined and for <code>process(result);</code> that it's used out of scope. Is it just mistaking the <code>{}</code> of the if statement for a more closed scope or should I really be doing it like this:</p>

<pre><code>var result;
if(condition){
    result = 1;
}else{
    result = 2;
}
process(result);
</code></pre>
