Skip to main content

DestructuringJS Syntax shorthand to extract elements from iterable & assign to Value

aka Destructure, Object-Destructuring, Array-Destructuring

destructured name & hours, then rename "name" field to shopName

const restaurant = { name: "Tesco", hours: 24 }

const { name: shopName, hours } = restaurant

apply default value of empty array to destructured object field of hours

const restaurant = { name: "Tesco" }

const { name, hours = [] } = restaurant

References