There are only two scenarios for JavaScript variable scopes: global scope, function scope
There is no code block scope, so develop a programming habit of declaring all variables (file headers, function headers).
function test () {
var abc= "123";
Efg= "456";
Put ("in Test abc=" +ABC);
Put ("in Test efg=" +EFG);
}
function Test1 () {
var abc;
Put ("in Test1 abc=" +ABC);
}
var abc= "abc";
var efg= "EFG";
Test1 ();
Put ("Before Test abc=" +ABC);
Put ("Before Test efg=" +EFG);
Test ();
Test1 ();
Put ("After test abc=" +ABC);
Put ("After test efg=" +EFG);
{
var abc= "www";
Put ("in Block abc=" +ABC);
}
Put ("Out Block abc=" +ABC);
Debugging information:
In Test1 abc=undefined
Before Test ABC=ABC
Before Test EFG=EFG
In Test abc=123
In Test efg=456
In Test1 abc=undefined
After Test ABC=ABC
After Test efg=456
In Block abc=www
Out Block Abc=www
This article is from the "idata" blog, please be sure to keep this source http://idata.blog.51cto.com/4581576/1100248