Can we pass a reference of a variable that is immutable as argument in a function?
Example:
var x = 0; function a(x) { x++; } a(x); alert(x); //Here I want to have 1 instead of 0
Since JavaScript does not support passing parameters by reference, you'll need to make the variable an object instead:
var x = {Value: 0}; function a(obj) { obj.Value++; } a(x); document.write(x.Value); //Here i want to have 1 instead of 0
1.4m articles
1.4m replys
5 comments
57.0k users