Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is default timeout in setTimeout() method of JavaScript Window object?

Tags:

According to W3Schools timeout is required parameter. But it is possible to call it without timeout parameter.

function eventHandler(e) {     var t = setTimeout(function () {         clearTimeout(t);         alert('Called');     }); } 
like image 779
Yuriy Rypka Avatar asked Aug 16 '13 14:08

Yuriy Rypka


People also ask

What is the default time on setTimeout JavaScript?

Specifies the function that will be executed. Not required. Specifies the time the function will be executed. 0 milliseconds by default.

Which is correct syntax of window setTimeout () method method?

The syntax is: setTimeout(function, milliseconds, parameter1, .... paramenterN); When you pass additional parameters to the setTimeout() method, these parameters ( parameter1 , parameter2 , etc.) will be passed to the specified function.

Why is setTimeout 0 used?

Invoking setTimeout with a callback, and zero as the second argument will schedule the callback to be run asynchronously, after the shortest possible delay - which will be around 10ms when the tab has focus and the JavaScript thread of execution is not busy.

What is the difference between setTimeout and window setTimeout?

window. setTimeout() . It's all the same method of the same object.


1 Answers

The HTML5 Timer spec says:

5) Let timeout be the second method argument, or zero if the argument was omitted.

like image 58
Bergi Avatar answered Oct 05 '22 17:10

Bergi