

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is javascript version of sleep()?
JavaScript does not have a native sleep function. There are however some workarounds you can use to get around this limitation. One of the easiest way to achieve sleep's functionality is to create your own sleep function using setTimeout and async/await.
Example
const sleep = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds)) // Using callbacks sleep(1000).then(() => console.log("waited 1 second!")) // Using async await const waitASec = async () => { await sleep(1000) console.log("waited 1 second!") } waitASec()
Output
waited 1 second! waited 1 second!
- Related Questions & Answers
- What is the JavaScript version of sleep()?
- JavaScript Sleep() function?
- Sleep in JavaScript delay between actions?
- Is the second string a rotated version of the first string JavaScript
- How do I check what version of Python is running my script?
- Which version of Firefox is compatible with selenium
- Which version is my MySQL?
- What is Cryogenic sleep and can it be put to practice practically?
- What is the use of a multi-version compatible jar in Java 9?
- Current Version of CSS
- Why it is important to sleep at noon?
- Modified version of summing an array with recursion in JavaScript
- Which is the selenium latest version?
- sleep() function in PHP
- Deep sleep in Arduino
Advertisements