20. What is destructuring assignment?

Destructuring is a JavaScript syntax feature that allows simplified access to array elements or object values.

const obj = {a: "stringA", b: "stringB"}; const {a, b: changedB, c} = obj; console.info(a, changedB, c) // stringA, stringB, undefined const arr = ["stringA", "stringB"]; const [A, B, C] = arr; console.info(A, B, C) // stringA, stringB, undefined

In object destructuring, variable names must match the object keys for proper assignment. If a variable name should be different, you can specify it after a colon. For array destructuring, the variable name is not crucial; what matters is the order.

Struggling to find common date to meet with your friends? Try our new tool commondate.xyz
devFlipCards 2025

Do you accept cookies?

Cookies are small amounts of data saved locally on you device, which helps our website - it saves your settings like theme or language. It helps in adjusting ads and in traffic analysis. By using this site, you consent cookies usage.

Struggling to find common date to meet with your friends? Try our new tool
commondate.xyz