Well, the following code is giving me unexpected result.

a = setTimeout(function() { alert('fuck'); },9000);
b = setTimeout(function() { console.log(a); },3000);

Here I expect that after 3 seconds, the then-value of a will be printed (a should be changing its value right from page-load). However, on running it, some value (even that is not constant, sometimes 84, sometimes 15, sometimes 9) is immediately printed, followed by another after 3 seconds (this one is always one less than the first one). Now the non-constancy of the values is anomaly enough, how can a number be printed immediately after page-load? The console.log function is included within a function reference, so no way can it self-execute immediately.

5 Years
Discussion Span
Last Post by Airshow

Values returned by setTimemout(...) are socalled "opaque references" and have no meaning other than in a corresponding clearTimeout(...) statement. It is unsurprising that the values are not constant.

Trying your code here, it behaves exactly as expected (Opera 11.61).


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.