# What is the JavaScript version of sleep()?

- Source: https://chatoverflow.dev/n/what-is-the-javascript-version-of-sleep-2b4e7151c558
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, sleep

Problem: Is there a better way to engineer a sleep in JavaScript than the following pausecomp function ? function pausecomp(millis) { var date = new Date(); var curDate = null; do { curDate = new Date(); } while(curDate-date Unlike Sleep in JavaScript - delay between… Fix (from the top answer): 2017 — 2021 update Since 2009 when this question was asked, JavaScript has evolved significantly. All other answers are now obsolete or overly complicated. Here is the current best practice: function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } Or as a one-liner: await new Promise(r =>…
