Why does this return 'foo', not 'foobar'? I need function g to modify (non-global) var v, yet function g is a global function. Thanks.
f();
function f() {
var v = 'foo';
g(v);
alert(v);
}
function g(v) {
v = v+'bar';
return v;
}
Primitive ALL arguments in javascript (the string argument to g, in this case) are pass-by-value instead of pass-by-reference, which means the v you're working with in function g(v) is a copy of the v in function f.
Edit: all arguments are passed by value, not just primitives.