you can not directly assign listener to javascript variable but you can do it indirectly in following manner.
you can save the value of a variable in a div or any html node
e.g.
<div id="variable-name" style="display:none;">variable-value</div>
or
<span id="variable-name" style="display:none;">variable-value</span>
and then use following js to monitor any change in the node.
This will work in YUI3 or above. ( I am not sure about YUI2.x)
var Y = YUI().use('node', 'event', function (Y) {
// node and event modules are loaded.
});
var demo = Y.one('#variable-name');
// And we can listen for DOM events.
demo.on('change', function (e) {
alert('value changed');
});
for more info about listening for events to YUI node
http://yuilibrary.com/yui/docs/event/#listening-for-events
and lists of events available
http://yuilibrary.com/yui/docs/event/#event-whitelist
EDIT
based on http://www.quirksmode.org/dom/events/change.html,
change event only fires if its form field
e.g. input
textarea
and select
so change event will not fire when contents of div is changed.