DEV Community

Mitesh Kamat
Mitesh Kamat

Posted on

9 1

Third argument in setTimeout()

Introduction

This is about the third argument in setTimeout function.

As we know, setTimeout allows us to run a function once after the interval of time.
This is the general syntax,

let timerId = setTimeout(func|code, [delay], [arg1], [arg2], ...)
Enter fullscreen mode Exit fullscreen mode

In day to day usage, we use setTimeout() like this:

function greeting(){
 alert('hey!!')
}
setTimeout(greeting,1000);
Enter fullscreen mode Exit fullscreen mode

Let's see how we can pass the third argument

function greeting(arg1, arg2){
 console.log(arg1,arg2)
}
setTimeout(greeting,1000,"Hi", "There");
//output: Hi There
Enter fullscreen mode Exit fullscreen mode

Instead of string we can pass an array, object, etc.

function greeting(arr){
 console.log(arr);
}
const arr = [1,2,3,4]
setTimeout(greeting,1000,arr);
//output:  (4) [1, 2, 3, 4]


function greeting(person){
 console.log(person);
}
const person = {name:"abc", age: 21}
setTimeout(greeting,1000,person);
//output: {name: "abc", age: 21}
Enter fullscreen mode Exit fullscreen mode

That's how you can make use of the third argument.
Cheers !!!

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (1)

Collapse
 
majedfaris profile image
majed L β€’

great

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay