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.

devFlipCards 2024

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.