Menu

JavaScript Destructuring Explained with Simple Examples
📰

JavaScript Destructuring Explained with Simple Examples

DEV Community: javascript·Lavkush Kumar·13 days ago
#XD96mXoS
#devtojavascript#devto#dev#destructuring#name
Long article (1681 words) — no AI summary yet.
Reading 0:00
15s threshold

Originally published on CodingCush .

JavaScript destructuring is a short way to pull values out of an array or an object into variables. Instead of writing const first = colours[0] and const name = user.name on separate lines, you unpack everything in one line. In this guide you will learn array and object destructuring, defaults, renaming, the rest operator, and destructuring in function parameters, with examples you can run in Node.js or your browser console. All code was run on Node.js v24.22.1.

What Is Destructuring in One Minute?

Imagine a suitcase packed with clothes. Without destructuring, you take items out one by one. With destructuring, everything lands in labelled boxes in one move. That is all it does: it unpacks values from an array or an object into separate variables in one statement.

const colours = [ "red" , "green" , "blue" ] ; const [ first , second ] = colours ; console .…

Continue reading — create a free account

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