I think JavaScript users mostly spend their time dealing with Objects. And for objects, we can call by reference as following.
let obj = { }
function f (parameter) { }
f(obj)
(parameter and obj refer to the same object, { })
However, I wonder if there is a way to apply this kind of work to primitive values.
let a = 0
function f (parameter) {
parameter = parameter + 1
}
f(a)
This won't work cause a and parameter are just different variables.
Is there any way to imitate following code from C?
void f (int* x) {
*x = *x + 1;
}
int main () {
int a = 0;
f(&a);