Destructuring function arguments

suggest change

Pull properties from an object passed into a function. This pattern simulates named parameters instead of relying on argument position.

let user = {
    name: 'Jill',
    age: 33,
    profession: 'Pilot'
}    

function greeting ({name, profession}) {
    console.log(`Hello, ${name} the ${profession}`)
}

greeting(user)

This also works for arrays:

let parts = ["Hello", "World!"];

function greeting([first, second]) {
    console.log(`${first} ${second}`);
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents