You Must Understand Reference Vs Value In JavaScript

preview_player
Показать описание


🌎 Find Me Here:

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

Such an important concept, wish I had learned this when I was first starting out

reggieriot
Автор

Interesting thing is that, internally strings are also stored as a reference. The difference is just that every operation makes a new reference.

Rakusan
Автор

I had a weird bug at work for the last few weeks that I just couldn't wrap my head around. This explains it. Thanks!

luisw.
Автор

This is really important when it comes to working with React hooks

Kim-byuy
Автор

That's why you learn C in college before anything else

marcola
Автор

This concept is extremely important to understand. It will help you with learning React and prevent annoying bugs in your code that can take you literal days to fix.

Xe
Автор

I love this sort of YT shorts. If anyone would ask me i'd never make much effort to learn it, because i feel like i don't need to know it. But learning through your shorts is so much easier than anything else. e.g. i was just eating and learned something new. Wouldn't have happened if this was in any other type of content i'd assume. So really, thank you!

AliveDeejay
Автор

You should go into more detail about string object storage. They are also stored as objects with references given to variables, but for all intents and purposes, can be treated like primitives/Numbers because of how they are stored. Almost all strings, created programmatically or with literals, are stored in a special cache throughout the life of the sandbox. So if you type in "let a='Hi'; let b='Hi'", both a and b will have the same memory reference. This is why you can use equivalency and equality operations on the two and will work as intended (i.e. a == b == 'Hi' and a === b === 'Hi')... a, b, and 'Hi' are all references to the same memory location and string object after interpretation!

pr
Автор

I understood it but never got it visualized like this in school! Very helpful Thanks!!

TheBen
Автор

Primitive Type vs Reference Type babyyy🔥🔥🔥

violetbabe
Автор

Wow! It's been explained to me many times, but this is the actual explanation!

blarvinius
Автор

omg simple so explained thank you sir much

ianthehunter
Автор

By reference we are actually targeting the variable itself by reading the memory location it resides in, and by value we're not, we are just taking a copy of whats in that memory location and doing something with that copy.

The first one (by reference) permanently changes whatever value is held inside variable at that memory location. The second one (by value), messes with a copy of whats held inside that variable at that memory location.

That is how I think it works.

The-Great-Brindian
Автор

Yo wait this mad useful this explains why people use spread all the time

spektree
Автор

Strings work the same, it is just that concatenation and other operations create new strings

antonpieper
Автор

i learned this the hard way, doing an app for a job and took me several days to realize this lol

NicolasSilvaVasault
Автор

Is there any way to get access to the address that the array points to?

herion
Автор

If you want to make a deep copy of an array or an object, you must use the "structuredClone" function

Ex:
const arr = [];
const newArr = structuredClone(arr)
arr.push("test")
console.log(newArr) //Returns []

LePhenixGD
Автор

So no ending character for each line commands?

josepheastman
Автор

no, I'm not going back to c-pointers

nobnobnobnob