37

Use Destructuring Assignment In JavaScript – Medium

 5 years ago
source link: https://www.tuicool.com/articles/hit/rIjUbqF
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

7NnuiuI.png!web

Introduce

In this article, I would like to share about Destructuring Assignment — an extremely useful syntax of JavaScript that I almost use it every day, every time I work with JS. According to the official definition on MDN , “Destructuring Assignment is a Javascript expression that allows to take the value (value) from within (array) or attribute (properties) in objects and assign new variables.” In the process of developing JS applications, we rarely work with one or two simple data types such as Number, String, etc., but often have to work with multiple data types, especially with data types. “synthetic” data like Object or Array (in JS, the array is also an Object). Destructuring Assignment helps us interact with Object in a scientific way and is much shorter than Es5 or older syntax, making code easy to read as well as increasing development speed and maintainability.

Use

In this section I will show the typical case of Destructuring Assignment when working with JS.

Use Destructuring Assignment to get the value from Object

In the case we get an Object and want to “peel” into separate values, for example var person = { name: ‘Viet’, age: 24, job: ‘dev’ } var name = person.name // name = ‘Viet’ var age = person.age // age = 24 var job = person.job // job = ‘dev’ .

Read More…


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK