February 2018
Intermediate to advanced
298 pages
8h 22m
English
You can also provide default values for the variables if the object property is undefined while destructuring. The following example demonstrates this:
let {a, b, c = 3} = {a: "1", b: "2"};
console.log(c); //Output "3"
Some property names are constructed dynamically using expressions. In this case, to extract the property values, we can use the [ ] token to provide the property name with an expression. The following example demonstrates this:
let {["first"+"Name"]: x} = { firstName: "Eden" };
console.log(x); //Output "Eden"
Read now
Unlock full access