Javascript scoping of variables
问题 The output is 15 (in f, x is taken to be 10 and y is 7) with the following: var x = 5; function f(y) { return (x + y) - 2}; function g(h) { var x = 7; return h(x) }; { var x = 10; z = g(f); console.log(z) }; Why did x take the value from the 4th line and not from the 1st line (and why not the 3rd line)? 回答1: var s are not blocked scoped, so the last line is equivalent to x = 10; z = g(f); console.log(z) It should be clearer now that the value of x was changed to 10 before f was executed. It