The following code during execution, the printed result is 1, Error: undefined;
function fn() { var x = y = 1; }
fn(); console.log(y); // 1; console.log(x); // Error: undefined;
The reason is that this function when execution is to be performed: y = 1; Since y here does not use var when declaring assignment, so by default be a global variable, then the value of a global variable is assigned to a local variable x ;
Its actual implementation process is as follows:
where y is 1 ; function fn () { where x = y; }