日期:2014-05-16 浏览次数:20456 次
function test(flat){ var t = "xx"; if(flat){ var k = "hehe";//k都出都有定义,不限于这个代码块 } for( var i=0;i<3;i++){//i也到处都有定义,不限于循环中 alert(i); } alert(i);//3 alert(k);//"hehe" }
function test(){ alert(i);//返回undefined 不会报错 var i = "hehe"; alert(i);//"hehe" }
var a = 3; var b = 3; b = 4; alert(a);//仍为3
var a = [1,2,3]; var b = a; b[0] = 99; alert(a);//[99,2,3]