# How do I pass a function by reference and then call it?

**URL:** <https://discourse.processing.org/t/how-do-i-pass-a-function-by-reference-and-then-call-it/27474>\
**Category:** Coding Questions\
**Created:** [January 30, 2021, 1:28am UTC](https://discourse.processing.org/t/how-do-i-pass-a-function-by-reference-and-then-call-it/27474 "2021-01-30T01:28:21Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 30, 2021, 6:14am UTC](https://discourse.processing.org/t/how-do-i-pass-a-function-by-reference-and-then-call-it/27474/3 "2021-01-30T06:14:35Z")

</div>

> [@thesuperdaine](#):
>
> … apparently JS doesn’t have pass by reference for primitives…

Actually JS functions, just like Java’s, are ALWAYS pass by value, regardless it’s a primitive or object datatype.

When we pass a variable as a single argument to a function, the current value stored in that variable is read, and then the invoked function’s receiving parameter is initialized w/ a copy of that read value.

B/c a function’s parameter can only receive a copy of the current value stored in a passed variable, reassigning another value to that local parameter won’t replace the value stored in the original passed variable.

Obviously if that value happens to be an object, mutating its properties via the local parameter will reflect on the original passed variable as long as that variable still stores that same object value.

---

_[View the full topic](https://discourse.processing.org/t/how-do-i-pass-a-function-by-reference-and-then-call-it/27474)._
