I want to set value to variable by another variable which will be reference to first variable.
see example below.
var white = 1;
var black = 15;
var flag = 'white';
if (flag == 'white') {
var color = &white;
color++;
} else {
var color = &black;
color--;
}
alert(white + ' ' + black);
//will display 2 15
// or
//will display 1 14
Many Thanks.
There is no true pass-by-reference in JS. However, I came up with this trick (objects are the only things in JS that are passed by reference):