Sleep function in JavaScript

Sometimes during debugging of a loading spinner on the frontend or to test the app behavior by adding delay in a certain function of the application, we need a sleep function just like in multithreaded languages like Java and C#Thread.Sleep(milliseconds).

I found a way to achieve this here in JS.

It will delay the execution for 10000 milliseconds(10 secs) between these two print statements.

thanks 🙌.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Syed Hassaan Ahmed
Syed Hassaan Ahmed

Written by Syed Hassaan Ahmed

Software Engineer (.NET , C# , JavaScript)

No responses yet

Write a response