const f = ({ a: a = 0, b: b = 1 }) => { ... }
I'm looking for an explanaition to why this doesn't work when I call f()
and it does when I call f({})
.
Main question: Is it possible to have an arrow function with destructured object passed as an argument, with it's properties being given default values if not defined?
undefined
is no object.
You could use a default object as well.
const f = ({ a = 0, b = 1 } = {}) => { console.log(a, b) };
f();