📖 INDEX
LOADING ENGINE...
JS Destructuring
Master the art of unpacking data in JavaScript.
destructuring.js
1/4
📦
A.D.A: Array destructuring is a shortcut to unpack values from arrays into distinct variables. Instead of using index numbers, we use a syntax that looks like an array literal.
JS Skill Tree
Basic Syntax
The left side of the assignment defines which variables to unpack from the sourced array.
System Check: Standard
How do you assign the first value of [1, 2] to a variable 'x'?
Concept Deep Dive
Swapping Variables
Normally, you need a temp variable. With destructuring, it's one line: [a, b] = [b, a]. This is the ultimate "Variable Ninja" move.
Functions & Arrays
Functions often return arrays (like useState in React). Destructuring is the standard way to handle those return values immediately.