JavaScript Named Parameters

September 27, 2020

Via Destructuring assignment

function test({name, age, address}={}) {
  console.log(`name=${name}, age=${age}, address=${address}`)
}
test({name: 'Desmond', age: 40, address: 'Kuala Lumpur'}) // name=Desmond, age=40, address=Kuala Lumpur

test({name: 'Desmond'}) // name=Desmond, age=undefined, address=undefined

test() // name=undefined, age=undefined, address=undefined
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.