mirror of
https://github.com/alrayyes/wiki.git
synced 2024-12-01 15:26:23 +00:00
667 B
667 B
id | title |
---|---|
eb8253f8-f376-4b73-9098-35da64a5a6e7 | Destructuring Default Values |
Basic syntax
const [x=3, y] = []
console.log(x, y) // 3 undefined
Computed on demand
Default values are computed when they are needed:
function tralala() {
return "tralala string"
}
const {computed=tralala()} = {}
console.log(computed) // tralala string
Refer to other variables
Default value an refer to other variables in the same pattern:
const [x=3, y=x] = []; // x=3; y=3
const [i=3, j=x] = [7]; // i=7; j=7
const [k=3, l=x] = [7, 2]; // k=7; l=2