declaring a variable twice in IIFE : <p>I came through this fun quiz on the internet.</p>

<pre><code>console.log((function(x, f = (() =&gt; x)){
  var x;
  var y = x;
  x = 2;
  return [x, y, f()]
})(1))
</code></pre>

<p>and the choices were:</p>

<ol>
<li><p>[2,1,1]</p></li>
<li><p>[2, undefined, 1]</p></li>
<li><p>[2, 1, 2]</p></li>
<li><p>[2, undefined, 2]</p></li>
</ol>

<p>I picked solution 2 TBH, basing that on that x has been redefined, y was declared and defined with no value, and that f has a different scope hence getting the global x memory spot than function x memory spot.</p>

<p>However, I tried it in <a href="https://jsbin.com/cakiheqita/1/edit?js,console" rel="noreferrer">jsbin.com</a></p>

<p>and I found it was solution 1, while I was not sure why that happened I messed with the function body and I removed <code>var x</code> from the function body, I found that the response changed to #3 which makes sense as x value changed and hence it showed x and f as 2 and y as 1 which was declared globally.</p>

<p>but still I can't get why it shows 1 instead of undefined.</p>
