r/ProgrammerTIL • u/night_of_knee • May 21 '18
Javascript [JS] TIL destructuring allows default values
Supplied default value will be used if the field is missing or undefined.
let { a, b = "bb", c = "cc", d = "dd", e = "ee", f = "ff" } = {
c: 33,
d: 0,
e: null,
f: undefined
}Result:
- a:
undefined - b: "bb"
- c: 33
- d: 0
- e: null
- f: "ff"
66
Upvotes
View all comments
Show parent comment
2
u/scallynag May 22 '18
And after ES6, it's now named per year, e.g ES2017