Tech Study

JavaScript SetTimeout() Function

The function or set of code gets executed when the time expires using JavaScript setTimeout() Method. A timer ID is returned, Timer ID or timeout can be removed using ‘clearTimeout()’ function.


JavaScript setTimeout() Method Syntax :


setTimeout(ricode, ridelay)


setTimeout(rifunctionRef, ridelay)

setTimeout(rifunctionRef, ridelay, riparam1)

setTimeout(rifunctionRef, ridelay, riparam1, riparam2)

setTimeout(rifunctionRef, ridelay, riparam1, riparam2, /* … ,*/ri paramN)

Parameters of JavaScript setTimeout() Method

Parameters :


A function that is to be executed when the timer expires.


Using a different syntax, we may supply a string rather than a function that will be constructed and executed after the timeout expires. The same security issues that come with using eval() apply to this syntax, thus it’s generally not recommended.

ridelay (Optional)

This is the time, in milliseconds for which the timer have to wait before the specified function or code is executed. If this parameter is deleted, a value of 0 will be used, which means execute “immediately”, or more precisely, the next event cycle.

We should note that in either case, the actual delay can be longer than intended; We can see the Reasons for delays that are longer than specified below.

We should also note that if the value is not a number, implicit type coercion is done silently on the value for converting it to a number — this can possibly lead to unexpected and surprising results; We can see Non-number delay values that are coerced silently into numbers taken as example.

riparam1, …, riparamN (Optional)

These are the additional arguments that are passed through to the function which are specified by rifunctionRef.

Return value

The returned timeoutID is supposed to be a positive integer value that identifies the timer created by the call to setTimeout().

It is generally guaranteed that a timeoutID value is never going to be reused by any consequent call to setTimeout() or setInterval() on the same object. 

C String Functions

C String Functions perform certain operations, It provides many useful string functions which can come into action. The <string.h> header …

Read more

Function Pointer in C++

Introduction : Function Pointer in C++ Pointers: In function pointer in c++ are the variables that consist of addresses of …

Read more