DEV Community 👩‍💻👨‍💻

chenge
chenge

Posted on

Fancy Function Parameters of JS

The code is from this post. It makes the params more clear.

function renderList(list, { 
    ordered = true,
    color = '#1e2a2d',
    bgColor = 'transparent'
} = {}) {
    /* ... */
}

// simple use
renderList(['love', 'patience', 'pain'])

// with all arguments
renderList(['one', 'two'], { ordered: true, color: '#c0ffee', bgColor: '#5ad' })

// with only one optional argument (bgColor)
renderList(['one', 'two'], { bgColor: '#5ad' })

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.