Ram

Lesson 11 of 20

Destructuring

Extract values from arrays and objects clearly.

Introduction

Destructuring assigns properties or positions to local variables in one readable statement.

It is useful when an API response contains several fields you need.

Key insight

Extract values from arrays and objects clearly.

Example

const user = { name: "Asha", city: "Kathmandu" };
const { name, city } = user;
console.log(name, city);

This example shows the core destructuring idea in a small, runnable program.

Real-world example

Components destructure props and functions destructure configuration objects.

Test yourself

2-question check

1

What is the main idea in Destructuring?

2

Where can destructuring be useful?

Ready to check your understanding?

Answer every question, then submit your quiz.

Try it yourself

JavaScript compiler

Runs in your browser. Nothing is sent to a server.

Output appears here

Practice challenge

Destructure the first two values from an array.

Previous
Next