Using '&&' as a shorthand if statement?
<p>While I was killing time looking up Javascript shorthand patterns, I came across an interesting way of expressing an <code>if</code> statement <a href="http://stackoverflow.com/questions/9319915/what-does-this-shorthand-do">here</a>. The following works:</p>

<pre><code>​var var1 = 5;
var var2 = 1;

var1 == 5 &amp;&amp; var2++;
</code></pre>

<p>I think that's a totally cool (and shorter, cleaner) way of writing an <code>if</code> statement that only needs to do one operation. However, I ran into an issue with the following code as soon as I tried something else with it:</p>

<pre><code>​var var1 = 5;
var var2 = 1;

var1 == 5 &amp;&amp; var2 = 2;
</code></pre>

<p>Instead of working like the first code snippet, my test throws an error:</p>

<blockquote>
  <p>Uncaught ReferenceError: Invalid left-hand side in assignment</p>
</blockquote>

<p>Why doesn't this work, and why is the left-hand side of my statement being called out as incorrect as opposed to the right hand?</p>
