BeginnerCoder

Lesson 1 — Destructuring & spread

Unpack values in one line

An object groups named values, like { name: "Alex", age: 20 }. Destructuring pulls several of those values out into variables at once: the names inside the curly braces must match the property names. Arrays work the same way with square brackets, but by position instead of by name.

const point = { x: 3, y: 7 };
const { x, y } = point;   // x is 3, y is 7
const [first] = ["a", "b"]; // first is "a"

Why it matters: modern JavaScript (and every React component) unpacks objects like this all the time, so you need to read it fluently.

Want it another way?
Task

Add one destructuring line so the program prints: Alex 20

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.