From 0afc6a15c63990267a009c3a94b325008040475e Mon Sep 17 00:00:00 2001 From: MariusTv <12083028+MariusTv@users.noreply.github.com> Date: Mon, 18 Feb 2019 05:21:46 +0200 Subject: [PATCH] ES6 Object destructuring - set default value (#31025) --- .../english/javascript/es6/destructuring/index.md | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/guide/english/javascript/es6/destructuring/index.md b/guide/english/javascript/es6/destructuring/index.md index 92fde76497..d94d76dc63 100644 --- a/guide/english/javascript/es6/destructuring/index.md +++ b/guide/english/javascript/es6/destructuring/index.md @@ -90,18 +90,16 @@ const {first: firstName, last: lastName} = fullName; console.log(firstName, lastName); // John Smith ``` -You can also use Destructuring on nested objects. - +A variable can be assigned a default, in the case that the value unpacked from the object is undefined. ```js -const person = {firstName: "John", lastName: "Smith", address: {city: "Istanbul", country: "Turkey"}}; -const {address: {city, country}} = person; +const person = { + age: 22 +}; -console.log(city, country); // Istanbul Turkey +const {name: firstName = 'Anonymous', age} = person; ``` -**Array Destructuring with rest** - -When destructuring an array, you can unpack and assign the remaining part of it to a variable using the rest pattern: +Destructuring an array with rest, you can unpack and assign the remaining part of it to a variable using the rest pattern: ```js const [a, ...b] = [1, 2, 3]; console.log(a); // 1