更新时间:2023-02-26 08:04:59
someF
creates a new (locally scoped) variable called someGlobal
(which masks the global someGlobal
) and assigns a value to it. It doesn't touch the global someGlobal
(although cannot access it because there is another variable with the same name in scope).
var
statements are hoisted, so someGlobal
is masked for all of someF
(not just after the var
statement). The value of the local someGlobal
is undefined
until a value is assigned to it.
someF2
access the original (untouched) global someGlobal
.