Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Destructuring Assignment

const HIGH_TEMPERATURES = {
  yesterday: 75,
  today: 77,
  tomorrow: 80
};

//ES6 assignment syntax
const {today, tomorrow} = HIGH_TEMPERATURES;

//ES5 assignment syntax
const today = HIGH_TEMPERATURES.today;
const tomorrow = HIGH_TEMPERATURES.tomorrow;

console.log(today); // 77
console.log(tomorrow); // 80
console.log(yesterday); // "ReferenceError: yesterday is not defined" as it should be.
Comment

destructuring assignment

Destructuring assignment is special syntax introduced in ES6, 
for neatly assigning values taken directly from an object.

const user = { name: 'John Doe', age: 34 };

const { name, age } = user;
// name = 'John Doe', age = 34
Comment

Destructing variable assignment

let profile = ['bob', 34, 'carpenter'];let [name, age, job] = profile;console.log(name);--> 'bob'
Comment

Destructuring assignment JS

const [firstElement, secondElement] = list;
// is equivalent to:
// const firstElement = list[0];
// const secondElement = list[1];

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
Comment

destructuring assignment in javascript

// destructuring assignment in javascript
// object destructuring
let person = { 
    name: "Chetan", 
    age: 30, 
    country: "India" 
};
const { name, age } = person;

console.log(name);
//expected output: "Chetan"

console.log(age);
//expected output: 30

console.log(country);
//expected output: Uncaught ReferenceError: country is not defined

// Array destructuring
const num = [1,2,3];
const [one, two, three] = num;
console.log(one); // 1
console.log(two); // 2
console.log(three); // 3
Comment

PREVIOUS NEXT
Code Example
Javascript :: foreach loop google script 
Javascript :: sequelize get all data 
Javascript :: javascript palindrome 
Javascript :: react hooks send data from child to parent 
Javascript :: react usememo vs usecallback 
Javascript :: set exit node tor 
Javascript :: react laravel 
Javascript :: how to check electron verion 
Javascript :: var js 
Javascript :: coderbyte first factorial solutions 
Javascript :: npm ERR! code E405 npm ERR! 405 Method Not Allowed - GET https://registry.npmjs.org/ 
Javascript :: select name get option value jquery 
Javascript :: get year javascript copyright 
Javascript :: get current date javascript full month 
Javascript :: javascript spread array without duplicates 
Javascript :: Get rid of white space around Angular Material modal dialog 
Javascript :: react 
Javascript :: what is node js 
Javascript :: javascript check if consecutive array 
Javascript :: convert object to url javascript 
Javascript :: mongoose nested object without id 
Javascript :: how to recognize an array in javascript 
Javascript :: Unable to resolve "@react-native-community/masked-view" from 
Javascript :: javascript appendchild before 
Javascript :: smtp js 
Javascript :: javascript get selected text 
Javascript :: javascript save data to local storage 
Javascript :: sort() object values javascript 
Javascript :: JavaScript super() keyword 
Javascript :: javascript how to open a file 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =