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?

If you upgraded to pro, sign in here

  • About
  • Blog
  • Privacy
Looking to email me? You can get me on my first name at allthecode.co