JavaScript Destructuring assignment Destructuring function arguments


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}`)


This also works for arrays:

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

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