📝 Edit page
➕ Add page
Mixed arguments
You can define positional arguments followed by keyword arguments.
function c(bazz, { foo, bar }) {
console.log('bazz', bazz)
console.log('foo', foo)
console.log('bar', bar)
}
c(1, {foo: 2, bar: 3})
// bazz 1
// foo 2
// bar 3
// OR
const x = { foo: 2, bar: 3 }
c(1, x)
// bazz 1
// foo 2
// bar 3
Note if you want to only pass keyword parameters, you need to make each of the positional arguments undefined
.
c(undefined, { foo: 2, bar: 3 })
// bazz undefined
// foo 2
// bar 3
Otherwise you will get avoid an error.
c({ foo: 2, bar: 3 })
// TypeError: Cannot destructure property 'foo' of 'undefined' as it is undefined.