30 Days Of JavaScript

Day 29: Mopping up

Lesson 3: Destructuring


JavaScript has a handy feature called destructuring. I've avoided introducing you to it so far, as it takes a little getting used to.

Let's start with the easier one.

Let's say you have an object and you want to access all the properties of it.

Having to access all the properties with pokemon. isn't the worst thing but it is a little cumbersome.

Instead we can declare all of those as variable and destructure the pokemon object into the,

This might not seem like the biggest win in this tiny example but trust me it's really handy.

You also don't need to grab all the properties, just the ones you want.

The names on your destructuring must match the name of the property in the object.

You can also do this with arrays as well, here the position is what matters and you can call them whatever you like.


Go Pro?

Upgrade to Pro for quizzes, tracked progress and a completion certificate for just $25 🚀

Want more developer tips, tricks and tools?
Then follow me:
FREE Coding Career Quick Start Guide 🚀
Discover the best way to learn to code, how to land a job and valuable resources to help your journey in this free 15 page value packed guide.
Looking to email me? You can get me on my first name at allthecode.co