Tech Study

JavaScript SetTimeout() Function

This method is provided by Javascript which guarantees the execution of a set of code after a certain time limit. This does not mean that the provided set of code runs exactly after the provided delay but it won’t be executed until that time period has elapsed. The `setTimeout` function returns an ID, also known as timeout id. The setTimeout operation can be cancelled using this ID by calling `clearTimeout()` and passing the ID to it as an argument.


JavaScript setTimeout() Method Syntax :


setTimeout(code, delay)


setTimeout(functionRef, delay)

setTimeout(functionRef, delay, param1)

setTimeout(functionRef, delay, param1, param2)

setTimeout(functionRef, delay, param1, param2, /* … ,*/ 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.

delay (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.

param1, …, paramN (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. 


const timeoutID = setTimeout(() => {
  console.log("run this code after 3 seconds");
}, 3000);



Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more