Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 884 Bytes

what_are_default_values_in_destructuring_assignment.md

File metadata and controls

22 lines (15 loc) · 884 Bytes

What are default values in destructuring assignment?

Default values in destructuring assignment allow you to assign a default value to a variable if the value being destructured is undefined. This is useful when destructuring objects or arrays with missing values.

Example with array:

let [x = 10, y = 20] = [5];
console.log(x, y);  // Output: 5 20

Example with object:

let { name = 'Guest', age = 25 } = { name: 'John' };
console.log(name, age);  // Output: John 25

Tags: intermediate, JavaScript, Destructuring

URL: https://www.tiktok.com/@jsmentoring/photo/7471727005394930966