JavaScript Value vs Reference Types

  Рет қаралды 95,254

Programming with Mosh

Programming with Mosh

6 жыл бұрын

JavaScript Value vs Reference Types
🔥Get the COMPLETE course (83% OFF - LIMITED TIME ONLY): bit.ly/2M1sp4B
Subscribe for more videos:
/ @programmingwithmosh
Want to learn more from me? Check out my blog and courses:
programmingwithmosh.com
/ programmingwithmosh
/ moshhamedani

Пікірлер: 69
@AriKariG
@AriKariG 4 жыл бұрын
My family is from Hamedan...Love your explanation of this topic really simplified, clean, and straight to the point.
@sodiqayilara1519
@sodiqayilara1519 3 жыл бұрын
No matter the amount of articles you have read,Mosh will always teach you something new and useful.Awesome teacher,thanks Mosh.
@NoahNobody
@NoahNobody 6 жыл бұрын
Wow, I didn't know that. I really need to improve my JS.
@lynnqi6451
@lynnqi6451 4 жыл бұрын
great explanation, very clear, straight forward. Help me a lot, thank you very much!
@ceddh15
@ceddh15 3 жыл бұрын
value vs reference was driving me crazy but this video absolutely helped me. thank you for the explanation
@anyakhardina6174
@anyakhardina6174 3 жыл бұрын
Another underlying principle worth mentioning here for the example starting at 3:05 is called "variable shadowing". Because our inner variable's name is the same as the outer variable's, a variable in the inner scope is said to shadow a variable in the outer scope. That is why we cannot re-assign a value assigned to a global variable. However, if you tweak this example a little bit: let number = 10; function increase() { number++; } increase(); console.log(number); So, here we are not passing in any arguments and therefore a value in the global variable can be re-assigned.
@cferracini
@cferracini 3 жыл бұрын
THANK YOU SO MUCH!!!! I researched a lot and the answer was right here in the comments! I was testing: *console.log('obj ',increase(obj));* *increase(obj);* and was getting undefined. I couldn't understand why... actually I don't fully understand yet. Because if I change: *function increase(x){ x++; }* *increase(obj);* *console.log('obj ', obj);* -> still gets 10. and *console.log('obj ',increase(obj));* -> still gets undefined is it because when we put "increase(obj);" obj becomes the x inside de function so we get the "variable shadowing" again? also... why do that function at all if it will only be able to deal with that one variable? it is easier to just put *obj++;* then print
@Navistar-cu2po
@Navistar-cu2po 11 ай бұрын
Clear, Concise, Straight to the point. Your video helped me grasp the concept quickly.
@han5173
@han5173 4 жыл бұрын
very straightforward and easy to understand! thank you!
@EnglishRain
@EnglishRain 4 жыл бұрын
FANTSTIC explanation! You're brilliant man! Hit home in first stroke!
@sdix20
@sdix20 Жыл бұрын
Excellent, concise explanation. Thank you, Mosh!
@aaabbb-qv4ff
@aaabbb-qv4ff 4 жыл бұрын
VERY nice explanation. Simple and to the point. Thank you!
@progtom7585
@progtom7585 4 жыл бұрын
this is excellent, im reading a "well regarded" book at the moment and its like double dutch compared to this simple explanation... thanks mate.
@mariekevandijk4
@mariekevandijk4 2 жыл бұрын
Brilliantly explained, thanks!
@nourslimane571
@nourslimane571 2 жыл бұрын
this explanation helps with every programming language , also one can learn about this fundamentally with C , great content.
@DS-zr9gv
@DS-zr9gv 4 жыл бұрын
Why are you so awesome at explaining. Please make more on Angular7 and JS
@rohitkudalkar92
@rohitkudalkar92 4 жыл бұрын
ooohhh, That was a very clear example. Thanks.
@abdelkrimeljaouhari2370
@abdelkrimeljaouhari2370 Жыл бұрын
you've made it very simple ,thanks.
@sakthi3687
@sakthi3687 6 жыл бұрын
Thanks Mosh 👍✌️😊... I am expecting ES6 features video
@a_maxed_out_handle_of_30_chars
@a_maxed_out_handle_of_30_chars Жыл бұрын
thank you, simple and to the point :)
@ablamohamedamine
@ablamohamedamine 4 жыл бұрын
Very useful Tutorial ! Thanks a lot :D
@ahmedabbas8774
@ahmedabbas8774 5 жыл бұрын
love you your videos very good explanation.
@11vag
@11vag 3 жыл бұрын
So far, the best explanation I´ve seen about this. Thank you mate.
@andTutin
@andTutin Жыл бұрын
the thing is. its wrong
@ZilverDx
@ZilverDx 5 жыл бұрын
Coming from C# to this I wasn't able to reference correctly a variable in JS. Thank You SO MUCH! Now I get it with this video!
@jmcauhy
@jmcauhy 5 жыл бұрын
Brasileiro tá em td lugar kkkk
@ciceroaraujo5183
@ciceroaraujo5183 4 жыл бұрын
You are really a great professor
@Dj7wiLLY
@Dj7wiLLY 2 ай бұрын
explained SOOOOOOOOOOO DAMN WELL !!!!!!!!!!!! Thank you so much, man !!!
@idrees9674
@idrees9674 3 жыл бұрын
Thanks, This really helped me
@danielakoyleek3757
@danielakoyleek3757 Жыл бұрын
Thanks sir. This was hard to get my head around til i watched this.
@ajaynathgupta
@ajaynathgupta 6 жыл бұрын
Nice explanation
@jsprodev2425
@jsprodev2425 6 жыл бұрын
Very helpful. Thumbs up
@tanvirmohammedakif5899
@tanvirmohammedakif5899 2 жыл бұрын
concept nicely explained, highly appreciated ///
@daniyahaider6468
@daniyahaider6468 2 жыл бұрын
i saw your video it was so interesting I thought it would be boring like other videos of other programers but when I started to see it the 6 mins gone away so fastly that I saw your video again and again and it was so fun can u make a video on symbols es6?
@AA-fe1zl
@AA-fe1zl 4 жыл бұрын
Excellent video!
@behindthescene2727
@behindthescene2727 2 жыл бұрын
Thank you sir
@s7s_space
@s7s_space 3 жыл бұрын
thanks Mosh
@drementer9
@drementer9 Жыл бұрын
🔥 awesome content
@sonamuhialdeen7866
@sonamuhialdeen7866 2 жыл бұрын
So good tutorial
@baatar
@baatar 4 жыл бұрын
You are great.
@KayhanEskanndari
@KayhanEskanndari Жыл бұрын
best explain ever
@bavan1358
@bavan1358 2 жыл бұрын
I almost gave up on this topic , you saved me
@javascript_developer
@javascript_developer 3 жыл бұрын
Thank again.
@carlosmedero2696
@carlosmedero2696 Жыл бұрын
Great explanation. I wish you wouldn't have named the parameters the same as the arguments. I would've understood it a bit sooner. Thank you!
@ashadcosta8756
@ashadcosta8756 2 жыл бұрын
A doubt - when we're consoling the value of x which is supposed to store the reference (address) of the object then why it is printing the object itself? Should not it print the address of the object as it is storing the same?
@PeriklesPeriklesoglu
@PeriklesPeriklesoglu Жыл бұрын
thanks
@mel7im19911
@mel7im19911 4 жыл бұрын
What about if we define Number/Strings as Objects, ex: let x = new Number (10) let y = x Is it will be assigned by reference or value?
@sagargahatraj5196
@sagargahatraj5196 3 жыл бұрын
refrence coz y is coping an object
@hesamdanaey5446
@hesamdanaey5446 3 жыл бұрын
reference i think. that is object now
@mohamedprogrammer19
@mohamedprogrammer19 Жыл бұрын
im happy cuuuuz i find this video
@LexRexLibertarian
@LexRexLibertarian 3 жыл бұрын
Great video but the scope pollution part confused me a bit
@rafaelcorrea7959
@rafaelcorrea7959 6 жыл бұрын
How do I force copying an object? (not by reference)
@samareshshil69
@samareshshil69 Жыл бұрын
great
@codeconceptswithmughees
@codeconceptswithmughees Жыл бұрын
So much better than my explanation 😅
@mindurownbussines
@mindurownbussines 5 жыл бұрын
in
@robertjones811
@robertjones811 5 жыл бұрын
Javascript is always pass by value. Pass by reference does not exist in JavaScript. When you remind yourself about the fact that an object and a reference to that object are 2 *independent* things, it will make more sense. I suppose we've been conflating and object "reference" and passing function arguments "by reference." stackoverflow.com/a/13104500/463206 stackoverflow.com/questions/37290747/pass-by-reference-javascript-objects#comment62108759_37290747 When passing a object reference, the *value* of that reference (e.g. the address of the object) is copied and that copy is passed - This is the definition of pass by value. "Pass by reference" means the original reference, not a copy, is passed. Here's the litmus test: In the called function assign a different object to the reference variable. If the original reference now points to this different object then you have pass by reference. But this does not happen in JavaScript. Of course you can change the object's properties, because the reference copy is pointing to the same object. But that is not germane. Rather, "Pass by xxxx" means - whatever you're passing, if it a copy it is "by value", if it is the original it is "by reference".
@HassanMalikTW
@HassanMalikTW 6 жыл бұрын
let number = 10; function inc(n) { number = number + n; } inc(5); number; // result is 15 HOW DOES THAT HAPPEN?
@davidsoto8445
@davidsoto8445 4 жыл бұрын
In case some else gets confused by this. see 0:34 of the video. This is by definition pass by reference.
@kayan_dev
@kayan_dev 4 жыл бұрын
let scoop is out of function increase
@francsicozuniga3721
@francsicozuniga3721 Жыл бұрын
Can anybody tell me what software or site he is using to demonstrate this? I am new to this and would really benefit from an app or something that lets you practice.
@ZTP357
@ZTP357 Ай бұрын
Visual Studio Code
@igu642
@igu642 11 ай бұрын
❤❤
@prateek4524
@prateek4524 3 жыл бұрын
🔥🔥🔥🔥🔥🔥
@mehmetedex
@mehmetedex 3 жыл бұрын
String is considered as an object and primitive type at the same time how confusing is that 🤣🤣🤣🤣🤣🤣
@Himanshu9178
@Himanshu9178 3 жыл бұрын
confused unga bunga
@rutumendhe3359
@rutumendhe3359 4 жыл бұрын
You should have given numbers for videos 😢😢 it's hard to find which is first and next video ... Content is good but navigation is hard 😢😢
@mek059
@mek059 5 жыл бұрын
Unfortunately I don't understand the concept :(
@andTutin
@andTutin Жыл бұрын
wrong
JavaScript Scope (Local vs Global)
5:43
Programming with Mosh
Рет қаралды 55 М.
Reference Vs Value In JavaScript
15:12
Web Dev Simplified
Рет қаралды 177 М.
Conforto para a barriga de grávida 🤔💡
00:10
Polar em português
Рет қаралды 84 МЛН
NO NO NO YES! (50 MLN SUBSCRIBERS CHALLENGE!) #shorts
00:26
PANDA BOI
Рет қаралды 92 МЛН
JavaScript - Reference vs Primitive Values/ Types
20:56
Academind
Рет қаралды 149 М.
JavaScript Tutorial for Beginners: Learn JavaScript in 1 Hour
48:17
Programming with Mosh
Рет қаралды 12 МЛН
Value Types and Reference Types in JavaScript
6:59
Programming with Mosh
Рет қаралды 16 М.
Primitive and Reference Data Types in JavaScript, Simplified
16:41
Deeecode The Web
Рет қаралды 599
9 Reasons People Hate JavaScript
4:45
Programming with Mosh
Рет қаралды 20 М.
JavaScript this Keyword
8:21
Programming with Mosh
Рет қаралды 441 М.
Learn JSON in 10 Minutes
12:00
Web Dev Simplified
Рет қаралды 3,1 МЛН
Is Coding Still Worth Learning in 2024?
9:33
Programming with Mosh
Рет қаралды 177 М.
Conforto para a barriga de grávida 🤔💡
00:10
Polar em português
Рет қаралды 84 МЛН