Lesson 15 of 15

Destructuring

Destructuring

Destructuring extracts values from arrays or objects into named variables in a single statement.

Array Destructuring

const [first, second, third] = [10, 20, 30];
console.log(first);   // 10
console.log(second);  // 20

Skip elements with commas:

const [, , last] = [1, 2, 3];
console.log(last);  // 3

Object Destructuring

const person = { name: "Alice", age: 30, city: "Paris" };
const { name, age } = person;
console.log(name);  // Alice
console.log(age);   // 30

Default Values

const { x = 0, y = 0 } = { x: 5 };
console.log(x);  // 5
console.log(y);  // 0  (default)

Your Task

Write function coordinates(point) that destructures point.x and point.y from the object argument and returns the string "(x, y)".

JavaScript loading...
Loading...
Click "Run" to execute your code.