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.

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).

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.