1
2
3
4
|
for ( var i=0; i < 10; i++){ doSomething(i); } alert(i); //10 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<html> <head></head> <body> <script type= "text/javascript" > var global_one = "I am global" ; function fun(){ global_two = "I am global too" ; var local_one = "I am local" ; } alert(global_one); // "I am global" //alert(global_two);// error //alert(local_one);//error fun(); alert(global_one); // "I am global" alert(global_two); // "I am global" //alert(local_one);//error </script> </body> </html> |
原文:http://www.cnblogs.com/Jacklovely/p/6388475.html