Code is extracted from getting started with es6
var x = 1;
function foo(x, y = function() { x = 2; }) {
var x = 3;
y();
console.log(x);
}
foo() // 3
x // 1
There is a sentence in .
Another internal variable x is declared inside thefunction foo, which is not in the same scope as the first parameter x because it is not in the same scope
then I modified
var x = 1;
function foo(x, y = function() { x = 2; }) {
let x = 3; //
y();
console.log(x);
}
my question is, since it is not the same scope, why can"t we declare x internally with let,
I know that variables cannot be repeatedly declared by let, but the answer says it is not the same scope
my question and guess:
does it not take into account the independent scope generated when the function has default parameters in the process of precompilation, so the duplicate definition is judged first?
feels strange, personal feeling: the compiler should declare the formal parameter x by let, so as to highlight the independent scope