example:
let x = 99;
function foo(p = x + 1) {
console.log(p);
}
foo() // 100
x = 100;
foo() // 101
However, if I change the parameters slightly to:
let x = 99;
function foo(x = x + 1) {
console.log(x);
}
foo() // NaN
x = 100;
foo() // NaN
Why is it displayed as NaN? What invisible changes occurred in the middle? If you know, can you tell me? Thanks
The following code is equivalent to
That is to say, the x in foo(x = x + 1) has nothing to do with the x outside. It is defined inside the function by you.
/a/11...
Of course not, I can do it if you want