diff --git a/es6.md b/es6.md index 7bf12fb52..1b9bc7f95 100644 --- a/es6.md +++ b/es6.md @@ -223,23 +223,30 @@ Default values can be assigned while destructuring arrays or objects. function greet({ name, greeting }) { console.log(`${greeting}, ${name}!`) } - -function add([ num1, num2 ]) { - console.log(`result: ${num1 + num2}`) -} - -function printCoordinates({ coordx: x, coordy: y }) { - console.log(`x: ${x}, y: ${y}`); -} ``` {: data-line="1"} ```js greet({ name: 'Larry', greeting: 'Ahoy' }) -add([2,4]) -printCoordinates({ coordx: 25, coordy: 90 }) ``` +Destructuring of objects and arrays can be also be done in function arguments. + +### Reassigning keys + +```js +function printCoordinates({ left: x, top: y }) { + console.log(`x: ${x}, y: ${y}`) +} +``` +{: data-line="1"} + +```js +printCoordinates({ left: 25, top: 90 }) +``` + +This example assigns `x` to the value of the `left` key. + ### Loops ```js