Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird random value as default interval handler parameter

Just came across this. It's not affecting anything really but i'm wondering why it's happening.

If I run the following code in firefox with firebug on:

setInterval(function(param) 
     {
        console.log("param is %o",param)
     },500);

param seems to be assigned a vaguely random value:

   param is -2
    param is -1
    param is -2
    param is 1
    param is -1
    param is 6
    param is -1
    param is 0
    param is -2
    param is 2
    param is 0
    param is 2
    param is 0
    param is 0
    param is 0
[..]
    param is 0
    param is 0
    param is 0
    param is 0
    param is 0
    param is 0
    param is 0
    param is 911
    param is 0
    param is 0
    param is 0
    param is -1

I do appreciate that I'm not passing any argument to setInterval to pass on to the function, but why does javascript chooses to pass this random number ?

I would have expected undefined or something like that...

Cheers

p.s. Haven't tested in other browsers

like image 875
Ben Avatar asked Jul 25 '26 00:07

Ben


1 Answers

It appears to be dependent upon Firefox's CPU usage.

I would guess that it's the delay from when the callback should have been called.

EDIT: I was right. It's the number of milliseconds late the callback was called.

like image 178
SLaks Avatar answered Jul 27 '26 13:07

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!