JavaScript Skip Function Arguments/Parameters

Nov 28, 2019
Named arguments

Solution 1

Assuming I wanted to call Date.toLocaleTimeString()

dateObj.toLocaleTimeString(locales, options)

To pass in options without locales

const date = new Date()var options = { timeStyle: 'full' }date.toLocaleTimeString(undefined, options)

Solution 2

function test(options) {    console.log(options.a, options.b, options.c)}
test({b: 'b', c: 'c'})  // undefined "b" "c"

Solution 3

function test({a, b, c}={}) {    console.log(a, b, c)}

NOTE: Require ES6 / ES2015

test({b: 'b', c: 'c'})  // undefined "b" "c"

❤️ Is this article helpful?

Buy me a coffee ☕ or support my work via PayPal to keep this space 🖖 and ad-free.

Do send some 💖 to @d_luaz or share this article.

✨ By Desmond Lua

A dream boy who enjoys making apps, travelling and making youtube videos. Follow me on @d_luaz

👶 Apps I built

Travelopy - discover travel places in Malaysia, Singapore, Taiwan, Japan.