A
Archos
I've a function in Go which uses a value by reference, and the output
is 4:
===
func byReference() {
x := 3
f := func(){
x = 4
}
y := &x
f()
println(*y) // 4
}
===
How would it be in JS? I've tried:
===
function byReference() {
var x = [3];
var f = function() {
x = 4;
};
var y = x;
f();
console.log(y[0] + "\n");
}
===
but it outputs 3.
I've followed this rule: `*x` is `x[0]` in javascript while `x` would
simply be `x`. For any value that is addressed, it is treates as if
it were boxed in an array.
is 4:
===
func byReference() {
x := 3
f := func(){
x = 4
}
y := &x
f()
println(*y) // 4
}
===
How would it be in JS? I've tried:
===
function byReference() {
var x = [3];
var f = function() {
x = 4;
};
var y = x;
f();
console.log(y[0] + "\n");
}
===
but it outputs 3.
I've followed this rule: `*x` is `x[0]` in javascript while `x` would
simply be `x`. For any value that is addressed, it is treates as if
it were boxed in an array.