Hackforge Academy

Category: javascript

Destructuring extracts

Published on 16 Jul 2026

Explanation

Destructuring extracts values from arrays into individual variables.

Code:

const colors = ['Red','Blue'];
const [first, second] = colors;

Explanation

Object destructuring extracts object properties into variables.

Code:

const user = {name:'John', age:25};
const {name, age} = user;

Explanation

Variables can be renamed during object destructuring.

Code:

const {name: userName} = user;

Explanation

Default values are used when a property is missing.

Code:

const {city='Chennai'} = user;

Explanation

Destructuring makes code shorter and easier to read.

Code:

function greet({name}) {
  console.log(name);
}

๐Ÿš€ Learn Spring Boot with real-world projects

๐Ÿ’ก Build REST APIs step by step

๐Ÿง  Improve backend development skills

๐ŸŽฏ Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

๐Ÿ

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
โš›๏ธ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
โ˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community