Understanding Passing by Reference or Value in JavaScript

This video tutorial explains the difference between passing by reference and passing by value in Javascript. Also discussed are the concept of passing and Primitive vs Object datatypes.
Code from Video: gist.github.com/prof3ssorSt3v...

Пікірлер: 28

  • @suelembezerra22
    @suelembezerra22 Жыл бұрын

    Finally soone who speaks in a calm way and getting to the point asap

  • @edwardm3552
    @edwardm3552 Жыл бұрын

    People who are wanting to fully understand JavaScript should go to this guy. You are so great at explaining things simply. Thank you.

  • @titokris5162
    @titokris5162 Жыл бұрын

    You always strive to pass understanding in your teaches, not just knowledge Thank you sir !!!!

  • @faizanahmed9304
    @faizanahmed9304 Жыл бұрын

    Thank you sir. I truly appreciate your hardwork and effort that you're putting to explain us.

  • @farrellkatz2633
    @farrellkatz2633 Жыл бұрын

    Thank you for the video on this key topic!

  • @endless3171
    @endless3171 Жыл бұрын

    Well explained, I came here from the previous passing by reference video by yours. Everything settled down in my mind after getting them one after another. Thank you sir.

  • @LearnEnglishwithKevin101

    @LearnEnglishwithKevin101

    Жыл бұрын

    Endless, which video is the previous one?

  • @endless3171

    @endless3171

    Жыл бұрын

    @@LearnEnglishwithKevin101 I couldn't find the video I was talking but nothing much different from this one. Maybe he replaced to this one.sry

  • @NedumEze
    @NedumEze Жыл бұрын

    So helpful. Thank you sir

  • @jaymzechapman9834
    @jaymzechapman9834 Жыл бұрын

    this was exactly what I needed to understand passing by reference. thank you for taking the time to do this.

  • @debhume4474
    @debhume4474Ай бұрын

    This was really helpful! Thank you!

  • @muhammadijaz6042
    @muhammadijaz60425 ай бұрын

    Excellent explanation 👍

  • @eduardcojocaru5674
    @eduardcojocaru5674 Жыл бұрын

    Thank you Professor! This is the best explanation that made it clear for me and I've seen many!

  • @hertechera
    @hertechera10 ай бұрын

    Thank you so much for this! Appreciate it so much

  • @TheNotoriousJS
    @TheNotoriousJS6 ай бұрын

    really good explanation. Thank you!!!

  • @amir7440
    @amir7440 Жыл бұрын

    The main difference between C and JavaScript is that in C, we explicitly pass the memory address of a variable to the function using pointers to achieve pass by reference, whereas in JavaScript, we do not explicitly pass a memory address, but rather pass a reference to the original object by value. So I think we do not have pass by reference in JS, all we have is pass a reference.

  • @peterlinddk

    @peterlinddk

    Жыл бұрын

    Correct! JavaScript only has “pass by value”. It seems that some of the confusion stems from that those values are references to objects or arrays. In fact I find the distinction between objects and primitives a bit detrimental. It would make more sense to think of mutable vs immutable objects. A number cannot be changed, when a variable is set = another number, it doesn’t change the number, but just like setting a variable = another object, changes what the variable points to. Note that every time someone says “it is a copy, so we don’t modify the original,” they set the variable = something new, and when they say “it is a reference, so we can modify the original” they use . to change some property or call a method on the object, that makes it mutate itself. There are no pass by reference in neither Java nor JavaScript.

  • @El_Bald
    @El_Bald Жыл бұрын

    Thanks for this great explanation ☺️

  • @Hussain-yv2xq
    @Hussain-yv2xq Жыл бұрын

    Thank You sir great explanation

  • @LearnEnglishwithKevin101
    @LearnEnglishwithKevin101 Жыл бұрын

    Thanks Steve, it helped me a lot getting through this subject. I'm currently on a learning path with Codecademy (which should learn from you) and Mosh Hamedani, but I'm sure when I'm done I will watch all of your videos. One question though: why did you use {} when logging the param? Thank you!

  • @SteveGriffith-Prof3ssorSt3v3

    @SteveGriffith-Prof3ssorSt3v3

    Жыл бұрын

    Inside console log you can get different versions of objects when you wrap the variable with { }. The { } will turn things like HTML elements into Objects with properties.

  • @General_Aladeen
    @General_Aladeen Жыл бұрын

    Thank you sir, hope you make a typescript tutorials.

  • @SteveGriffith-Prof3ssorSt3v3

    @SteveGriffith-Prof3ssorSt3v3

    Жыл бұрын

    Maybe someday.

  • @PixelLoafLatte
    @PixelLoafLatte Жыл бұрын

    Ah thank you steve, i am new to js and just meet this problem, but how can i copy the value to new object?

  • @SteveGriffith-Prof3ssorSt3v3

    @SteveGriffith-Prof3ssorSt3v3

    Жыл бұрын

    If the value is a Primitive then the value will be copied. If the value you want to copy is an Object then it is only a reference that is copied. To create a copy of an object you can convert it to a JSON string, or pass it through localStorage, or pass it through a Message, or you can recursively loop through the object making copies of all the primitives inside the object and copying them into a new object, or there is a new method called structuredClone. JSON - kzread.info/dash/bejne/Yp9osNmincnZqqQ.html localStorage - kzread.info/dash/bejne/moN3u7Cdl9a7ltY.html Messaging - kzread.info/dash/bejne/oGaCx6WFhLizhKg.html (first video in the playlist) structuredClone - video coming soon

  • @webb-developer
    @webb-developer5 ай бұрын

    done ☑

  • @LuciendelMar
    @LuciendelMar Жыл бұрын

    I believe there is a little fault in the logic of this demonstration as the "num" you're logging out on line 35 is not the "num" you are passing into the function on line 40, but is simply the "num" variable declared on the global scope. To prove it, if you pass into the function some other number variable, you will get the same console result... :)

  • @SteveGriffith-Prof3ssorSt3v3

    @SteveGriffith-Prof3ssorSt3v3

    Жыл бұрын

    Yes. num is the global variable. The function is demonstrating that we are NOT changing the original variable - num. param is a new variable that has a copy of num.