Clean up your code using object destructuring in Javascript #shorts

preview_player
Показать описание
I use object destructuring all the time for grabbing properties from an object.

------------

Рекомендации по теме
Комментарии
Автор

I love these bite sized a few a day will help clean up some practices for newbs

MichaelImo
Автор

i find these kids of videos interesting, they all show a way to improve your javascript code, but then proceed to show something that i’ve known of and have been using for a long time. However, I love to watch these as a refresher of what I can do. Keep these up:)

DieselJS
Автор

Great short introduction!

I think de-structuring is a useful tool that can increase code readability. However, I also think it's also good to know that de-structuring can hurt code readability as well. Overuse of de-structuring can make it harder to understand variable scope.

For example, say a function takes in as an argument a single object, 'bar'. Bar has a property 'foo'. The function could take in 'bar' as an argument, or take in a de-structured version of the object { foo }. Using 'bar.foo' instead of 'foo' can help distinguish it from local variables used within the function.

Essentially my opinion is that in some cases you may not want to de-structure because it makes it easier to understand where a variable originates from. So, even though it can often be a good option, it's not always the option.

yukarix
Автор

Thanks allot...this tips helps us junior/ intermediate developer

gedeonchrist
Автор

Ty a lot, u make a big deal for community

romansamon
Автор

I do these to deconstruct my props in react all the time. Very helpful

BruceWayne-rtsu
Автор

can also use object destructuring to remove a object key/s from an existing object.

more like “delete Object.key” but one liner if you have multiple

keent
Автор

How to make the error highlighting like in the video?

shadowplay
Автор

const [, ,,address,] = user
hence you can skip all, only take address.

kizhissery
Автор

What extension do you have that VSC gives inline errors

moederkoek
Автор

Does the name of the variables actually have any meaning? I think this is dependent on the position of the variables in the object right? If I swap name and age will the result be the same?

italoaugustooliveira
Автор

why cant you just create new variables that store them like let name = 'foo' instead of using let obj = { 'name': 'foo' } with let name = obj.name? sorry, just trying to understand how objects work

cyncxd
Автор

So sometimes in JavaScript you JavaScript the JavaScript variables JavaScript JavaScript new object JavaScript.

rileyschenk