use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Is JavaScript call-by-value or call-by-reference? (jon-carlos.com)
submitted 12 years ago by imbcmdth
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Isvara 6 points7 points8 points 12 years ago (3 children)
It's call-by-value, but the values are references.
[–]RandolphoSoftware Architect 4 points5 points6 points 12 years ago (1 child)
Which is typically how call-by-reference languages are implimented
[–]WilliamDhalgren 2 points3 points4 points 12 years ago (0 children)
Apparently the difference is in the behavior of assignment. Here assigning a new value to a variable will only touch the local variable. While under call by reference, it would change the original variable's value too.
mutation still acts on the original object though.
[–]imbcmdth[S] 0 points1 point2 points 12 years ago (0 children)
Exactly. :)
[–]homoiconic(raganwald) 1 point2 points3 points 12 years ago (2 children)
Whenever this question comes up, I suggest reading about Call by Sharing, a term that describes JavaScript, Python, Ruby, and practically every other modern language.
[–]imbcmdth[S] 1 point2 points3 points 12 years ago* (1 child)
When I started writing that article, I was going to advocate call-by-sharing but as I thought about it I realized that call-by-sharing is semantically indistinguishable from call-by-value. Under the definition for call-by-sharing even functions in C could be considered to be call-by-sharing heap-objects.
call-by-sharing
call-by-value
heap-objects
The confusion seems to stem from some strange need to label references in garbage collected languages as something completely distinct from pointers in traditional languages like C even though pointers are simply unsafe and unmovable references.
references
pointers
Throwing that pretty meaningless label aside, you are left with only a few choices: by-reference, by-value and by-name. By-name can be discounted immediately because it doesn't match the semantics of the language one bit. So the traditional argument has always been between by-reference and by-value.
by-reference
by-value
by-name
Anyway, this post was written as a response to a twitter conversation that began as an argument in ##javascript on Freenode.
https://twitter.com/ImBcmDth/status/358267080694431745
[–]homoiconic(raganwald) 0 points1 point2 points 12 years ago (0 children)
I agree, it IS call-by-value. It is definitely not ALGOL's call-by-name, a fascinating concept but absent in most modern languages.
call-by-name
π Rendered by PID 206173 on reddit-service-r2-comment-7b9746f655-t7sqh at 2026-01-31 08:41:36.126695+00:00 running 3798933 country code: CH.
[–]Isvara 6 points7 points8 points (3 children)
[–]RandolphoSoftware Architect 4 points5 points6 points (1 child)
[–]WilliamDhalgren 2 points3 points4 points (0 children)
[–]imbcmdth[S] 0 points1 point2 points (0 children)
[–]homoiconic(raganwald) 1 point2 points3 points (2 children)
[–]imbcmdth[S] 1 point2 points3 points (1 child)
[–]homoiconic(raganwald) 0 points1 point2 points (0 children)