JavaScript consts Aren't Constants - JavaScript Quick Fix

preview_player
Показать описание
Does JavaScript treat constant arrays and objects the same way as numbers, strings, and booleans? Turns out not. So let's see why that is and how, if you don't understand it, you can easily put bugs into your React applications.

👉 What's my theme? Night Wolf [black]
👉 What's that font? Operator Mono

Thank you for watching this video, click the "SUBSCRIBE" button to stay connected with this channel.

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

Every video I watch from this channel make me realize every time that I'm still walking in the dark
Thanks for today's light Jack👍🏾

frankkevy
Автор

I was literally watching the creator of redux saying it really don't matter whether to use let or const bc const can be mutated too. And this popped up on my notifications, life is so weird sometimes.

dgcp
Автор

Just found you last week Jack. And I can't stop watching 👀

drewbird
Автор

Jack, your videos are always awesome, thanks! Just wanted to quickly add that Object.freeze() will make object properties immutable at runtime (shallow freeze only). I don't see it used often because--as you mentioned--it's relatively inexpensive to create shallow clones of objects and pass references to them instead of the original. However, there are a few proposals to TC39 involving Object.freeze() under the hood (defensible classes/frozen prototypes, and a new proposed syntax for Object.freeze() and Object.seal()), so I thought it was worth mentioning :)

seatube
Автор

This is a very clear explanation of an essential notion.

chrislr
Автор

Thanks Jack please keep this videos coming everyday, God bless you.

AbdelhameedG
Автор

Object.freeze can be also useful to make arrays and objects, well... truly constants.
But I still can't wait for Records and Tuples coming to JavaScript - they seem really nice.

Will_U
Автор

THANK YOU for this video. Finally I understand _why_ we need to destructure objects when changing state. I sometimes wish JS syntax could be a bit more clear about what's a "real" value and what's just a memory location.

MrKeepItTrill
Автор

Interesting explanation, normally I use "readonly" keyword for objects and "const" for primitive in TS (with Angular)

prmming
Автор

As others have said, object.freeze() helps here. But also if you use Typescript you can make your object or array readonly

JBuchmann
Автор

Primitive datatypes are passed by value and Non primitive data types are passed by reference.

akashtakawale
Автор

hey just had a doubt regarding the useState example, lets assume the useState is an array containing 10k objects. while updating state using setState, since we will need destructure the current state array of objects every time, this thing won't be performant enough. How can we oversome this issue @JackHerrington

solowolf
Автор

Thanks, Jack for the awesome videos, Really appreciate it.

shubhamlatiyan
Автор

There's always object.freeze if you really need to limit.

darkmift
Автор

Thanks for the video, very informative.

JulioDx
Автор

Hi Jack awesome session. I was wondering which tool you use for painting on your screen with a pen in that rainbow colors?

NilsLutz
Автор

I've been reading through the 2nd edition of You Don't Know JS, and in it, Kyle Simpson (the author) suggests to only use const for primitive values, while using let (or var) for all other values in order to alleviate some of this confusion. I was wondering what your thoughts on that stance are?

captstrugglebunny
Автор

Ah, the eternal pain of stack and heap, where naive dreams of value equality go to die :S

PhilipAlexanderHassialis
Автор

Great video! Also should we actually spread the previous state which is passed in first param as setState is async? Like setState(prev => ({ …prev, name: “nee”})

shreyas.jadhav
Автор

Doesn’t Object.freeze also kind of help?

aleksd
visit shbcf.ru