-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is JavaScript Pass by Reference? #36
Comments
Very high quality blog. Thank you for the information. |
Amazing! Thank you! |
This is THE best, in-depth explanation I have read on passing by reference and by value--thank you so much! |
Amazing explanation of a pretty tough concept for most. Well done, this is 100% going in my bookmark list to refer back to! |
I can not understand the ambiguous term "pass-by-reference" until I read this blog! Thank you! |
cleared my misconception |
Great article, I could've lost my mind and got that wrong but.. |
@Goteii Not a silly question!
No, the scenario you describe is how JavaScript currently works: If you pass an object to a function, you can access and mutate any of its properties, and the change will be reflected outside the function. If JavaScript did support passing by reference, we could change an object reference to point to an entirely new object inside a function, and that change would be reflected outside the scope of the function: const swap = (objectA, objectB) => {
const tempObject = objectA;
objectA = objectB;
objectB = tempObject;
}
const a = { value: 24 };
const b = { value: 42 };
swap(a, b); If JavaScript supported pass by reference, |
No description provided.
The text was updated successfully, but these errors were encountered: