Destructuring in JavaScript

From the JavaScript cheat sheet · Modern JavaScript (ES6+) · verified Jul 2026

Destructuring

Extracting values from arrays and objects

javascript
// Object destructuring
const { name, age } = person;
const { x: newX, y: newY } = point;

// Array destructuring
const [first, second] = array;
const [head, ...tail] = array;

// Function parameters
function greet({ name, age = 18 }) {
  // use name and age
}
💡 Use default values to handle undefined properties
⚡ Rest operator must be last in destructuring pattern
📌 Destructuring is shallow, not deep copying
🔥 Great for extracting multiple return values

More JavaScript tasks

Back to the full JavaScript cheat sheet