Could you propose any workarounds to implement a reference to variable using closures or any other tricks?
createReference = function() { // TODO: how to
In JavaScript, you can't pass primitive values (numbers, strings, etc) by reference. However, every object you pass will always be by reference. (this includes arrays)
To use your example:
var foo = { x: 5 }; var refFoo = foo; // foo.x => 5 // refFoo.x => 5 foo.x = 6; // foo.x => 6 // refFoo.x => 6