DEV Community

Cover image for Very Large Delay Value In setTimeout
capscode
capscode

Posted on • Originally published at capscode.in

Very Large Delay Value In setTimeout

Hello Dev,

In this article, I will explain you 1 very important limitation of setTimeout in JavaScript.

Browsers including Internet Explorer, Chrome, Safari, and Firefox store the delay as a 32-bit signed integer internally. This causes an integer overflow when using delays larger than 2,147,483,647 ms (about 24.8 days), resulting in the timeout being executed immediately.

function func(){
    setTimeout(()=>{
        console.log('Print hello after 2,147,483,648 milliseconds')
    }, 2147483648)
}

func() 

Enter fullscreen mode Exit fullscreen mode

Expected output/ behavior for the above code should be the callback function of setTimeout will execute after 2,147,483,648 milliseconds.

But the callback function will get executed immediately because the maximum delay value in setTimeout is 2,147,483,647 milliseconds and we have provided 2,147,483,648 milliseconds as delay.

Thank you for reading this so far. This is a brief introduction on How Large Delay Value In setTimeout Acts in JavaScript.

Hope it's a nice and informative read for you.
If you find this article useful, like and share this article. Someone could find it useful too.

If you find anything technically inaccurate, please feel free to reach out to us.

VISIT https://www.capscode.in/blog TO LEARN MORE.

See you in my next Blog article, Take care!!

Thanks,
CapsCode

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

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

Okay