How to Wait 1 Second in JavaScript w3schools Tutorial

Logan Jul 13, 2026

When working with JavaScript, there are times when you might need to pause the execution of your script to allow other processes to complete, or to create a delay for effects or animations. In such cases, you may want to make your script wait for a second. JavaScript does not natively support waiting or pausing scripts, but we can utilize built-in methods or external libraries to achieve this.

The JavaScript Cheat Sheet Every Beginner Wishes They Had
The JavaScript Cheat Sheet Every Beginner Wishes They Had

In this article, we will explore several ways to create a one-second delay in JavaScript, using both straightforward methods and external libraries, and refer to w3schools for code snippets and examples.

JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)

Using built-in methods

JavaScript provides a few built-in methods that can be used to create delays in your code. The two most common are setTimeout() and setInterval().

JavaScript Basics You MUST Know
JavaScript Basics You MUST Know

setTimeout() method calls a function after a specified number of milliseconds. This makes it ideal for creating a one-second delay. Here's how you can use it to wait for one second:

Using setTimeout()

Fun JavaScript Coding Project Ideas for Beginners: Practice Front End Web Development (in 2020)
Fun JavaScript Coding Project Ideas for Beginners: Practice Front End Web Development (in 2020)

setTimeout() takes two arguments: a function to be executed, and a delay time (in milliseconds). To pause your script for one second, you would use:

<strong>JavaScript</strong> setTimeout(function() { // Your code here will execute after a 1-second delay }, 1000);

The function inside setTimeout() will run after 1000 milliseconds, or 1 second.

For creating an eternal loop with a one-second delay, you can use setInterval(). However, this is generally not recommended for heavy tasks as it can cause your script to run indefinitely until stopped.

⏳ Master JavaScript setTimeout(): Delay Code Execution Like a Pro! 💻✨  Pin Description:
⏳ Master JavaScript setTimeout(): Delay Code Execution Like a Pro! 💻✨ Pin Description:

Using setInterval()

setInterval() method calls a function repeatedly, with a specified delay between each call, until stopped. Here's how you can use it for a one-second delay loop:

<strong>JavaScript</strong> var intervalId = setInterval(function() { // Your code here will execute every 1 second }, 1000); // To stop the interval, use: clearInterval(intervalId);

This will run the function inside setInterval() every 1000 milliseconds, or 1 second, until clearInterval() is called.

Learn JavaScript in the Right Order 🚀
Learn JavaScript in the Right Order 🚀

Using external libraries

While built-in methods like setTimeout() and setInterval() are sufficient for most use cases, there are times when you might want to use an external library for more advanced functionality. Here, we'll discuss one popular library, async, that can help manage asynchronous operations and delays.

Best JavaScript Projects for Beginners to Practice
Best JavaScript Projects for Beginners to Practice
Javascript tutorials
Javascript tutorials
JavaScript Web Development Cheat Sheet: Your Essential Guide - Connect 4 Programming
JavaScript Web Development Cheat Sheet: Your Essential Guide - Connect 4 Programming
Javascript Fundamental
Javascript Fundamental
Javascript String Methods
Javascript String Methods
an info sheet with different types of web pages
an info sheet with different types of web pages
Mastering JavaScript Array Iteration Methods in Just a Minute |  Part 1 | Geekboots
Mastering JavaScript Array Iteration Methods in Just a Minute | Part 1 | Geekboots
Cheat Cheat on JavaScript Loops
Cheat Cheat on JavaScript Loops
Easiest way to learn JavaScript.
Easiest way to learn JavaScript.
JavaScript Basics for Beginners | Learn JS Step by Step
JavaScript Basics for Beginners | Learn JS Step by Step
JavaScript calculator projet
JavaScript calculator projet
🚀 Master JavaScript Loops: For, While, Do-While, For-In & For-Of Loops Explained! 💻✨
🚀 Master JavaScript Loops: For, While, Do-While, For-In & For-Of Loops Explained! 💻✨
JavaScript study guide for fast learning
JavaScript study guide for fast learning
JavaScript | Chapter 2 📖| Part 1 ✨
JavaScript | Chapter 2 📖| Part 1 ✨
Javascript Cheet cheet
Javascript Cheet cheet
JavaScript Project Ideas For beginners
JavaScript Project Ideas For beginners
javascript Fundamental
javascript Fundamental
Javascript Loops & Iterations
Javascript Loops & Iterations
10 Must-Know JavaScript Shorthand Techniques
10 Must-Know JavaScript Shorthand Techniques

Using async/await with Promises

The async and await keywords allow you to write asynchronous code that looks and behaves like synchronous (sequential) code. To create a one-second delay using async/await, you can use a Promise:

<strong>JavaScript</strong> async function waitForOneSecond() { await new Promise(resolve => setTimeout(resolve, 1000)); // Your code here will execute after a 1-second delay } waitForOneSecond();

The waitForOneSecond() function will pause the execution of your script for one second using a Promise that resolves after the specified time.

Always remember that creating too many delays or blocking the main thread can negatively impact your application's performance. Use these methods judiciously and consider user experience when implementing delays in your code.

Practice creating delays with different methods and see which one works best for your specific use case. Visit w3schools JavaScript tutorial for more examples and in-depth explanations.

Now that you've learned various ways to make your JavaScript script wait for one second, it's time to apply this knowledge and experiment with delays in your projects. Happy coding!