From the course: Learning ECMAScript 6+ (ES6+)
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Destructuring objects - JavaScript Tutorial
From the course: Learning ECMAScript 6+ (ES6+)
Destructuring objects
- [Instructor] A handy feature that you'll see used widely in JavaScript applications is destructuring. So let's use a simple example to get us started. We're going to create a sandwich object, and the sandwich object will have title, it'll have a price, a description, and some ingredients. Now, if I wanted to console.log some of the values from the sandwich, I could. I could say... let's just log the whole sandwich first.... and then I could say sandwich.title... that'll give us the Reuben... and we could access anything using that dot notation. Now let's update this a bit to include the variables with destructuring. So instead of sandwich, we're going to use the curly braces. So this is different than a ray destructuring. Objects always have the curly braces. And then we're going to select what we want from that object, so title and price. Now, when I run this, we're going to see that sandwich is no longer defined,…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.