Javascript Destructuring Assignment With Default Value
Destructuring assignments can have default values.
const [one, two, three = "tres"] = ["uno", "dos"]
console.log(three) // "tres"
const { uno, dos = "two", tres } = { uno: "one", tres: "three" }
console.log(dos) // "two"
The same goes for function parameters.
function foo({ uno, dos = "two", tres }) {
console.log(dos) // "two"
}
foo({ uno: "one", tres: "three" })
See Also⌗
Read other posts