修改let

This commit is contained in:
Ruan Yifeng
2015-03-04 18:51:25 +08:00
parent 5618f6e5e7
commit db97b33931
3 changed files with 18 additions and 4 deletions
+13
View File
@@ -167,6 +167,19 @@ foo(2) // 2
上面代码中,参数y的默认值等于x,由于处在函数作用域,所以x等于参数x,而不是全局变量x。
参数变量是默认声明的,所以不能用let或const再次声明。
```javascript
function foo(x = 5) {
let x = 1; // error
const x = 2; // error
}
```
上面代码中,参数变量x是默认声明的,在函数体中,不能用let或const再次声明,否则会报错。
参数默认值可以与解构赋值,联合起来使用。
```javascript