Is there any way for a variable to act as a reference to another variable? Could I have multiples variable all hold the same information regarding a single piece of data?
For example:
var foo = "data";
var bar = foo;
// I want this to set both foo & bar to null
foo = null;
console.log(bar); // However, bar is still set to "data"
In C or C++ you're able to get this desired behavior with pointers; having two variables reference the same location in memory.
Is there some way to mimic this behavior in JavaScript?
bto some non-nullpointeraand then setatonull, pointerbwill still point to the non-nullplace in memory. (That's not to say that you can't get the desired behavior in C++ with pointer references.)foowas anObj*andbarwas also anObj*and they both pointed to the sameObj, iffooorbarchanged theirObjvalue then the update would appear to both variables.vartochar *).