DEV Community

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

Posted on

10 2

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.

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more