javascript code like this
function foo (x = 2,y = function(){return x;}){
var x = 5;
console.log(y()) // 2
}
foo();
console output 2,it's looks like the parameters has own scope and closure the parameter x .until i see this result:
function foo (x = 2,y = function(){return x;}){
x = 5;
console.log(y()) // 5 WTF?
}
foo();
console output 5.this is really confused me.Is keyword var make a redeclaration and be ignore?but looks not work like this. How this code really work in this case?