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 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 :: discord.js change role permissions 
Javascript :: fly: javascript fly 
Javascript :: Pignose Calender 
Javascript :: Calling JSON REST Services with FoxPro and wwJsonServiceClient 
Javascript :: react usestate vs variable 
Javascript :: google script delete line 
Javascript :: immutable js sort ascending and descending order 
Javascript :: how to make password star star on input html 
Javascript :: reactvs y axis range 
Javascript :: errorMessage 
Javascript :: create dots in carousel react js bootraps 
Javascript :: scenery 
Javascript :: negate expression prolog 
Javascript :: agora token Renewal 
Javascript :: cancellable function 
Javascript :: prototip 
Javascript :: two jq events 
Javascript :: how to change selected link in jquery 
Javascript :: factorial recursion javascript 
Javascript :: leap year javascript 
Javascript :: listen to changes in children of div in html 
Javascript :: Viewport ch. 
Javascript :: How to select a search bar without a `name`? javascript 
Javascript :: this in js class method 
Javascript :: pagination component 
Javascript :: Fibonacci perticular position in javascript 
Javascript :: how to pass data to ejs partials 
Javascript :: regex expression for password uppercase lowercase specil character , number in js 
Javascript :: Truncate a Stringtarget 
Javascript :: how to search table using jquery 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =