Sunday 17 February 2019

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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...