Tuesday, 20 March 2018

About the scope in javascript,why the following not output 21 but 22?

function t()
{
var x = 1;
if(true)
{
var x = 2;
alert(x);
}
alert(x);
}
t();


Anyone knows the reason?

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...