码迷,mamicode.com
首页 > Web开发 > 详细

前端面试题之JS篇

时间:2015-07-14 15:07:08      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

1.var a=b=3的执行顺序

var a,b;

(function(){
    alert(a);
    alert(b);
    var a=b=3;
    alert(a);
    alert(b);
})();
alert(a);
alert(b);
 
输出结果:undefined,undefined,3,3,undefined,3
参考:http://stackoverflow.com/questions/27329444/why-a-is-undefined-while-b-is-3-in-var-a-b-3

Since a will be defined in local scope and b will be defined in global scope. Inside function both aand b are 3 but after function returns registered local variable (a) is deleted. Since b is defined in global scope it is not deleted.

var a=b=3

Is the same as:

var a = (b = 3)

And var statement applies only to a, and not to b. You can check the syntax of var statementhere.

前端面试题之JS篇

标签:

原文地址:http://www.cnblogs.com/michael-xiang/p/4645289.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!