Add default values example for destructured function arguments

This commit is contained in:
Rauno Freiberg 2018-02-16 16:22:04 +02:00 committed by GitHub
parent 7cc4382d9b
commit d177021cb2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 0 deletions

14
es6.md
View File

@ -232,6 +232,20 @@ greet({ name: 'Larry', greeting: 'Ahoy' })
Destructuring of objects and arrays can be also be done in function arguments.
### Default values in destructured function arguments
```js
function greet({ name = "Rauno", greeting = "Hello" } = {}) {
console.log(`${greeting}, ${name}!`);
}
```
{: data-line="1"}
```js
greet() // Hello, Rauno!
greet({ name: 'Larry' }) // Hello, Larry!
```
### Reassigning keys
```js