简体   繁体   中英

Can anybody explain me the output of this code?

This is the code I am compiling.

var a = 10;
var c = 5;
b(40);

function b(x) {
  a(20);
  a=40;
  c=50;
  function a() { console.log(x);}  
}

console.log(a);
console.log(c);

Can you tell me the output and explain it?

40 10 50

First b(40) will be executed. Then a(20) which will ignore the 20 and print the x (currently 40). Then a will be set to 40 and c to 50. Then both of them will be printed in line 12 and 13.

40 10 50

the second one is 10 bc the a declared in b() isn't the same var as the one declared in the beginning (just execute the code).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM