mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2024-04-21 12:32:22 +00:00
修改let
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user