Skip to main content
FREE Mock interview & resume review with Sumit. Free right now, no payment needed.Book a slot

Destructuring

Topic 1JavaScript Part 5 (Important Keywords)

Destructuring

Introduction

Destructuring is a syntax introduced in ES6 that allows unpacking values from arrays or properties from objects into distinct variables in a concise manner.

Key Concepts and Definitions

Destructuring

A syntax introduced in ES6 that allows unpacking values from arrays or properties from objects into distinct variables in a concise manner.

Examples

Array Destructuring:

const fruits = ['Apple', 'Banana', 'Cherry'];
const [first, second, third] = fruits;

console.log(first); // Apple
console.log(second); // Banana
console.log(third); // Cherry

Object Destructuring:

const person = { name: 'Alice', age: 25, city: 'New York' };
const { name, age, city } = person;

console.log(name); // Alice
console.log(age); // 25
console.log(city); // New York

Default Values:

const [a = 1, b = 2] = [];
console.log(a, b); // 1, 2

Interview guide discussion

(0)

Join the discussion — login to comment and help other developers.

Login to comment
Destructuring | JioCoder