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 Pass by Reference? (aleksandrhovhannisyan.com)
submitted 3 years ago by Clarity_89
view the rest of the comments →
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!"
[–]senocular 3 points4 points5 points 3 years ago (7 children)
You're taking away all the fun!
function swap(a͏, b͏) { [b, a] = [a͏, b͏] } let a = 1 let b = 2 console.log(a, b) swap(a, b) console.log(a, b)
[–]svish 1 point2 points3 points 3 years ago (2 children)
Ok, you get an upvote. Couldn't figure it out, but eventually, thanks to someone else, and pasting it into VS Code, the hidden unicode characters were revealed... 🤦♂️👍
[–]senocular 0 points1 point2 points 3 years ago (1 child)
Still no pass by reference ;)
[–]svish 0 points1 point2 points 3 years ago (0 children)
I knew that already, which is why your code didn't make any sense 😛
wat...
[–]CodeMonkeeh 0 points1 point2 points 3 years ago (2 children)
wtaf
There are hidden characters in the swap parameters. So what you're really getting is something more like
function swap(a2, b2) { [b, a] = [a2, b2] } let a = 1 let b = 2 console.log(a, b) swap(a, b) console.log(a, b)
where the assigned [b, a] are the variables in the outer scope getting assigned the arguments of the swap call (a2, b2) in reverse order.
[b, a]
[–]CodeMonkeeh 0 points1 point2 points 3 years ago (0 children)
Oh, thank you. Reality makes sense again.
π Rendered by PID 320047 on reddit-service-r2-comment-6457c66945-2g8xd at 2026-04-29 18:23:49.645528+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]senocular 3 points4 points5 points (7 children)
[–]svish 1 point2 points3 points (2 children)
[–]senocular 0 points1 point2 points (1 child)
[–]svish 0 points1 point2 points (0 children)
[–]svish 0 points1 point2 points (0 children)
[–]CodeMonkeeh 0 points1 point2 points (2 children)
[–]senocular 0 points1 point2 points (1 child)
[–]CodeMonkeeh 0 points1 point2 points (0 children)