DEV Community

Maditusi
Maditusi

Posted on

It took me 3 years to understand Destructuring in JS

Hi,

my name is Madina and I'm trying to transition into junior developer role.
I started my journey long time ago. I paused, took breaks, questioned my life choices and current state is that I'm doing an online bootcamp (65% done) ✅

I did all the courses on JS, which you can only imagine, any format: YouTube tutorials, blogs, courses paid & free...

It took me 3 years to grasp on the concept of Destructuring in JS. I just couldn’t get it. Now I can tell that I finally understood it)

Given an object

let person = {
  "userId": 1,
  "id": 1,
  "title": "delectus aut autem",
  "completed": false
}
Enter fullscreen mode Exit fullscreen mode

I don’t want the whole object, just some parts of it:

const { userId, title } = person;

Enter fullscreen mode Exit fullscreen mode

So, Destructuring is a way of cutting pieces of a cake 🎂 🍰

let cake = { 🎂 }
Enter fullscreen mode Exit fullscreen mode

Results in

let { 🍰 } = 🎂
Enter fullscreen mode Exit fullscreen mode

I hope it could help someone out there!

Top comments (0)