var test = [10, 20, 30];
(function()
{
var testFunc = function(myVar)
{
myVar[4] = 10; // works
myVar.push(10); // works
myVar = [1, 8]; // fails
};
testFunc(test);
})();
console.log('test:');
console.log(test);
As you can see, assigning a new array to the variable that was passed by reference will not work correctly. Javascript works so weird. Changing the "passed by reference variable" works. But assigning a new type to it (which should also be passable by reference) does not...
(function()
{
var testFunc = function(myVar)
{
myVar[4] = 10; // works
myVar.push(10); // works
myVar = [1, 8]; // fails
};
testFunc(test);
})();
console.log('test:');
console.log(test);
As you can see, assigning a new array to the variable that was passed by reference will not work correctly. Javascript works so weird. Changing the "passed by reference variable" works. But assigning a new type to it (which should also be passable by reference) does not...