标签:
大家来补充
1.变量类型模糊,容易出现问题;
2.全局变量与函数内部变量同名时,在函数内部声明变量,声明位置虽然在后,但在这之前,此名变量已为‘undefined’;
var a = ‘aaa‘; function b() { console.log(a); var a = ‘bbb‘; console.log(a); } b(); console.log(a);
输出:
undefined
bbb
aaa
3.浮点数运算BUG,例如7*0.8=5.6000000000000005;
4.变量传递,对象为引用传递,数字和字符串是值传递;即函数内不能改变变量地址
var a = {};
var b = ‘我是b1‘; a.name = ‘aaaa‘; (function(a,b) { a.name = ‘bbbb‘;
b=‘我是b2‘; a = {}; a.name = ‘cccc‘; console.log(a.name);
console.log(b);
})(a,b);
console.log(a.name);
console.log(b);
输出cccc,我是b2,bbbb,我是b1
暂时写这点,请大家来补充
标签:
原文地址:http://www.cnblogs.com/shuchong/p/5911167.html