函数和变量
var a = 100; function fn() { alert('1:'+a); var a = 200; alert('2:'+a); } fn(); alert('3:'+a); var a; alert('4:'+a); var a = 300; alert('5:'+a);
alert 结果:1:undefined
2: 200
3: 100
4: 100
5: 300
var a = 100; function aa(){ console.log(a) }; aa(); 结果:100
var a = 100; function aa(){ console.log(a); var a = 100}; aa();
结果:undefined