var q = (function(x,foo = () => x) {
console.log('a)',x,y,foo()); //2 undefined 2
var x;
console.log('b)',x,y,foo()); //2 undefined 2
var y = x;
console.log('c)',x,y,foo()); //2 2 2
x =3;
console.log('d)',x,y,foo()); //3 2 2
return [x,y,foo()];
})(2)
console.log(q) // [3,2,2]
var q = (console.log('init q',typeof x), //init q undefined
function(x,foo = (console.log('init foo',x),() => x)) { //init foo 2
console.log('a)',x,y,foo()); //2 undefined 2
var x;
console.log('b)',x,y,foo()); //2 undefined 2
var y = x;
console.log('c)',x,y,foo()); //2 2 2
x =3;
console.log('d)',x,y,foo()); //3 2 2
return [x,y,foo()];
}
)(2)
console.log(q) // [3,2,2]