Is there an equivalent in JavaScript for PHP’s reference passing of variables?
[PHP]:
function addToEnd(&$theRefVar,$str)
{
$theRefVar.=$str;
}
$myVar="Hello";
addToEnd($myVar," World!");
print $myVar;//Outputs: Hello World!
How would the same code look in JavaScript if possible?
Thank you!
Objects are passed as references.
Edit:
foois a reference to an object and that reference is passed by value to the function.The following is included as another way to work on the object’s property, to make your function definition more robust.