Demo 1
Create new Javascript file named demo1.js. This file contains code demo as below:
let person = { firstName: 'John', middleName: 'Smith', lastName: 'Thomas' };
let { firstName, lastName, middleName } = person;
console.log('First Name: ' + firstName);
console.log('Middle Name: ' + middleName);
console.log('Last Name: ' + lastName);
Run Demo 1
Use node demo1.js statement run code demo
First Name: John
Middle Name: Smith
Last Name: Thomas
Demo 2
Create new Javascript file named demo2.js. This file contains code demo as below:
let animal = {
dog: 'Dog 1',
cat: {
bigger: 'Cat 1',
smaller: 'Cat 2'
},
turtle: 'Turtle 1'
};
const { dog, turtle } = animal;
console.log(dog + ', ', turtle);
const { bigger, smaller } = animal.cat;
console.log(bigger + ', ' + smaller);
Run Demo 2
Use node demo2.js statement run code demo
Dog 1, Turtle 1
Cat 1, Cat 2