函数和变量

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

 

 

posted @ 2017-03-01 13:49  GIScript  阅读(121)  评论(0编辑  收藏  举报