Object Destructuring: Extracting Object Properties

Understand the differences between extracting object data in a traditional way and using object destructuring with the help of examples.

Enhanced object literals, which you saw earlier in the chapter, provide a nice way to create an object using values from variables in lexical scope. Object destructuring is the opposite; it provides an elegant way to extract data from objects into variables in local or lexical scope.

Traditional way to extract object data

Let’s extract the data from an object using the hard way first and then see how object destructuring helps. Suppose we have an object that holds a person’s details.

Get hands-on with 1400+ tech skills courses.