AceDevHub
Beginner JavaScript Interview QuestionsBeginnerConcept

JavaScript · Question 21

What is destructuring in JavaScript?

Direct answer

Destructuring is syntax for unpacking array elements or object properties into variables, parameters, or assignment targets.

Array destructuring is positional: const [first, second] = items;. Object destructuring is property-based: const { name, age } = user;.

  • Values can be renamed, such as const { id: userId } = user.
  • Default values can be provided when the extracted value is undefined.
  • Rest syntax can collect remaining items or properties.
  • Destructuring is commonly used in function parameters to make required fields explicit.