DEV Community

Cover image for Pass by value/reference :EXPLAINED WITH SINGLE GIF (Believe me it's true)
Raghav Khanna
Raghav Khanna

Posted on

Pass by value/reference :EXPLAINED WITH SINGLE GIF (Believe me it's true)

Look at this GIF and i bet you will understand the basic difference between pass by value vs. Pass by reference.

Alt Text

Give a like!
If you find this amazing 😄

Top comments (1)

Collapse
 
aplich profile image
Arek Plich

Gif can be very confusing by implying that after passing an object as a method argument, you can do whatever you want with it without changing the original object.

As you know, only the reference to the object is copied (finally we have two references) which still points to the same object and any modification to it will be reflected in the source object (on the heap) to which these references point.

The above gif only applies in the context of passing primitives.