A topic about the scope of JS functions
related codes
var xyx = 1;
function fx(){console.log(xyx)}
var xyx = 2;
fx();
The result of the output is 2.
isn"t it supposed to look from the inside to the outside of the fx function declaration, and then find out that xyx is 1, and then output it? Why did it become 2? Is there something wrong with my understanding? please give me some advice. thank you!