Destructuring Assignment with Functions in ECMAScript

Create new Javascript file named demo1.js. This file contains code demo as below:

function showInfo({ firstName, lastName, age }) {
    return `Name: ${firstName} ${lastName}
            Age: ${age}`;
}

const person = {
    firstName: 'John',
    lastName: 'Thomas',
    age: 18
}

console.log(showInfo(person));

Use node demo1.js statement run code demo

Name: John Thomas
Age: 18




Create new Javascript file named demo1.js. This file contains code demo as below:

let options = {
    title: "My menu",
    items: ["Item1", "Item2"]
};

function showMenu({ title = "Untitled", width = 200, height = 100, items = [] }) {
    console.log(`${title} ${width} ${height}`);
    console.log(items);
}

showMenu(options);

Use node demo2.js statement run code demo

My menu 200 100
[ 'Item1', 'Item2' ]