Real random value as a default interval handler parameter

Just stumbled upon this. This does not really affect anything, but I wonder why this is happening.

If I run the following code in firefox with firebug:

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

it seems to be assigned an undefined 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 understand that I am not passing any setInterval argument to pass the function, but why does javascript decide to pass this random number?

I would expect undefined or something like that ...

Greetings

ps not tested in other browsers

+3
source share
2 answers

It seems to depend on the use of the Firefox processor.

, callback.

EDIT: . , .

+3

, window.setInterval. , ( )

var intID = window.setInterval( function(){ alert("I'm annoying!"); }, 10000 );

// this will kill it before it annoys you, :D
window.clearInterval( intID );

window.setTimeout:

var timeID = window.setTimeout( function(){ alert("I'm annoying!"); }, 10000 );

// this will kill it before it annoys you, :D
window.clearTimeout( timeID );
0

Source: https://habr.com/ru/post/1729326/


All Articles