In a browser like Chrome or Firefox (firebug) you could run the program step by step, inspect the value, etc...
Besides, you cannot force Javascript to trigger an event when x changes.
However you could make a function (setx), having x global, or having setx a nested function within a function where x is defined:
function setx(v) {
alert("x changes!");
x = v;
}
Then instead of doing
x = 7;
you do
setx(7);
and the alert is triggered. Replace all x assignments with a call to setx and you'll be notified whenever x changes, ie whenever setx is called.
This is of course basic cross-browser JS.