In JavaScript The output of the below code snippet is [2,1,2]
function func(x, f = () => x) {
var y = x;
x = 2;
return [x, y, f()];
};
console.log(func(1));
In JavaScript output of below code snippet is [2,1,1]
function func(x, f = () => x) {
var x;
var y = x;
x = 2;
return [x, y, f()];
};
console.log(func(1));
I was expecting both the code snippets to have same output. But it is not the case.