1.允许函数参数带默认值
ES6 之前,不能直接为函数的参数指定默认值
function method(x,y=10){
console.log(x, y);
}
method(20); //20 10
(1)参数变量是默认声明的,所以不能用let或const再次声明
function foo(x = 5) {
let x = 1; // error
const x = 2; // error
}
(2)函数上传递参数 解构赋值
function fn({x,y,z}){
console.log(x, y, z);
}
fn({x:1,y:2,z:3}); //1 2 3
2.作用域 (笔试题)
var x=1;
function foo(x){
var x=3;
let y= function () {x=2};
y();
console.log(x);
}
foo(); //2