local variables - Does javascript implement lexical scoping? -
this question has answer here:
why return 2 instead of 1? seems second "var" silently ignored.
function foo() { var local = 1; { var local = 2; } return local; } foo() /* 2 */
in javascript there function level scope , global scope. cannot create block scope , adds no special meaning , not create scope.
and how code ends up
function foo() { var local = 1; local = 2; return local; } foo();
in es6 can create block level scopes of let. es6 not supported yet. more on here
Comments
Post a Comment