I have a variable whose value is partly defined in terms of another variable. I want to change the value of that variable so that the initial variable also changes. But this doesn’t happen. Look at the second line:
var offset = 0;
var message = "the number is " + offset;
If I modify offset
, then message
doesn’t change:
console.log(message); // This says "the number is 0".
offset += 20; // `offset` is changed to `20`.
console.log(message); // The message is still "the number is 0".
message
, in this case, would then be called a “reactive” variable.
Why doesn’t it work, and how would I solve it?