1.let的使用
let是声明变量,与var的区别是作用域更小
function fors(){
for (var i=0;i<=5;i++) {
console.log(i);
}
console.log(i+1);
}
fors(); //1,2,3,4,5,7
function fors2(){
for (let i=0;i<=5;i++) {
console.log(i);
}
console.log(i+1);
}
fors2(); //1,2,3,4,5 i is not defined
2.箭头函数
相当于匿名函数
fn = x=> x*x;
fn(2) //4
3.数组辅助,
[a,b] = [b.a+b];
相当于python中的 a,b = b,a+b
起到的效果是 t = a
a = b
b = t+a
4. js的判断简化写法
greeting=(visitor==”PRES”)?”Dear President “:”Dear “; 如果 visitor ==
‘pres’ greeting = Dear President 否则 greeting==Dear 相当于python中的
greeting = Dear President if visitor == “PRES” else Dear
(ms == 0) ? jQuery(“#dk_kj”).hide(): jQuery(“#DKKJ_MONEY”).val(ms);