title: Scope of variables inside inline function default parameter
body: <p>ES6 introduced <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters" rel="nofollow noreferrer">default parameters</a>. I'm trying to understand how inline function default parameters work with this new feature. Specifically how its scoping work.</p>
  
  <p>Take for example the following two functions:</p>
  
  <pre><code>function one(x, f = function (){return x})
  {
      var x = 5;
      console.log([x,f()]);
  }
  
  function two(x, f = function (){return x})
  {
      x = 5;
      console.log([x,f()]);
  }
  
  one(1);//[5,1]
  two(1);//[5,5]
  </code></pre>
  
  <p>Is it correct to say that, in function one, <code>f</code> keeps it's own closure scope for <code>x</code> in the parameter list, so that when the function redefines x as a new var: <code>var x = 5;</code>, the reference that <code>f</code> has, is not the same as the one inside the function?</p>
  
  <p>If that's the case, is function one equal to function three below:</p>
  
  <pre><code>function three(x,f)
  {
      var x2 = x;
      f = f !== undefined ? f : () =&gt; x2;
      var x = 5;
      console.log([x,f()]); //[5,1]
  }
  </code></pre>
  
  <p>I tried, without luck, to find how this behavior is documented, if someone could point me to the right part of the documentation that would also be great.</p>