Javascript simplified if-statement
<p>I'm scratching my head trying to understand this very simplified if statement. When searching for the answer, all I find is answers related to ternary operators.</p>

<p>Anyway. Why is it that the first case below works, while the latter throws an <code>ReferenceError</code>? Just trying to understand how things work.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>true &amp;&amp; alert("test")</code></pre>
</div>
</div>
</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var x;
true &amp;&amp; x = 10;</code></pre>
</div>
</div>
</p>