Menu

Post image 1
Post image 2
1 / 2
0

Destructuring in JavaScript

DEV Community·Pratham·23 days ago
#c0lFXt94
Reading 0:00
15s threshold

Unpack values from arrays and objects into neat, individual variables — in a single line. Here's a pattern I used to write all the time before I learned about destructuring: const user = { name : " Pratham " , age : 22 , city : " Delhi " , }; const name = user . name ; const age = user . age ; const city = user . city ; console . log ( name ); // "Pratham" console . log ( age ); // 22 console . log ( city ); // "Delhi" Enter fullscreen mode Exit fullscreen mode Three lines just to pull values out of an object and assign them to variables. It works, but it's repetitive. You're typing user. three times, and if the object had 10 properties, you'd have 10 lines of essentially the same pattern. Destructuring lets you do all of that in one line: const { name , age , city } = user ; Enter fullscreen mode Exit fullscreen mode Same result. One line. No repetition. When I first saw this in the ChaiCode Web Dev Cohort 2026, it felt like a cheat code. Let me show you how it works. What Does Destructuring Mean?…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More