Tuesday, 19 April 2016

local variables - Does javascript implement lexical scoping?

Why does this return 2 instead of 1? Seems the second "var" is silently ignored.




function foo()
{
var local = 1;
{
var local = 2;
}
return local;
}
foo()
/*

2
*/

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...