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.