Featured Article

Master Promises in JavaScript W3Schools Tutorial Guide

Adam Jul 13, 2026

Promises in JavaScript, offered by W3Schools as part of their extensive tutorial of web development, are a key concept when working with asynchronous operations. They help in handling callbacks, making your code cleaner and more maintainable. Let's dive into promises, their syntax, and usage, guided by W3Schools' step-by-step lessons.

Promises
Promises

W3Schools' promise tutorials start by explaining what promises are. In simple terms, a promise is an object that holds either a "fulfilled" value, a "rejected" value, or is still in a "pending" state, waiting for an operation to complete. It's a way to handle asynchronous operations and represents the eventual completion or failure of an asynchronous operation.

Promise Intro in JavaScript
Promise Intro in JavaScript

Creating Promises

W3Schools walks you through creating, handling, and chaining promises. To create a promise, you wrap the asynchronous code in the constructor of the Promises object, as demonstrated in their interactive examples.

⭐️🎀 JavaScript Visualized: Promises & Async/Await
⭐️🎀 JavaScript Visualized: Promises & Async/Await

Here's a simple breakdown of creating a promise, as shown in the W3Schools tutorial:

Syntax

a white screen with some type of programming code on it's back side and the words asynchronous code everywhere in java script
a white screen with some type of programming code on it's back side and the words asynchronous code everywhere in java script

The syntax to create a promise is as follows:

var promise = new Promise(executor);

The executor is a function with two arguments: resolve and reject, which are functions that you use to "fulfill" or "reject" the promise respectively.

Example

Promise & Async await in JavaScript.
Promise & Async await in JavaScript.

Let's create a simple promise that fulfills after 1 second, using W3Schools' code as a reference:

var promise = new Promise(function(resolve, reject) { setTimeout(() => resolve("Resolved!"), 1000); });

The promise, when executed, awaits the setTimeout function for 1 second, then calls the resolve function, "fulfilling" the promise and making it return "Resolved!".

Consuming Promises

a black screen with colorful text on it
a black screen with colorful text on it

W3Schools also provides insightful lessons on consuming promises. Promises are consumed using the .then(), .catch(), and .finally() methods.

For instance, to handle a fulfilled promise, you use .then(). If the promise is rejected, you use .catch(). And .finally() is used to execute code no matter if the promise was fulfilled or rejected.

What Are the Benefits of Using Promises?
What Are the Benefits of Using Promises?
Quiz: 9 JavaScript Promise Questions
Quiz: 9 JavaScript Promise Questions
Javascript: Powerful with Promise like a Professional
Javascript: Powerful with Promise like a Professional
🤝 Promise.allSettled() VS Promise.all() in JavaScript 🍭
🤝 Promise.allSettled() VS Promise.all() in JavaScript 🍭
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
10 JavaScript Concepts Every Beginner Must Know (Save This Cheat Sheet!)
10 JavaScript Concepts Every Beginner Must Know (Save This Cheat Sheet!)
an image of a diagram that shows the process to create a web page for a website
an image of a diagram that shows the process to create a web page for a website
In Which State Can a Promise Be?
In Which State Can a Promise Be?
JavaScript Full Notes Every Beginner Must Save 💡
JavaScript Full Notes Every Beginner Must Save 💡
JavaScript Reserved Words: What You Need to Know 🚀
JavaScript Reserved Words: What You Need to Know 🚀
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)
Javascript Fundamental
Javascript Fundamental
Learn JavaScript in the Right Order 🚀
Learn JavaScript in the Right Order 🚀
JavaScript Template Literals: Write Cleaner & Dynamic Strings 📝
JavaScript Template Literals: Write Cleaner & Dynamic Strings 📝
Functions in Javascript
Functions in Javascript
JavaScript Web Development Cheat Sheet: Your Essential Guide - Connect 4 Programming
JavaScript Web Development Cheat Sheet: Your Essential Guide - Connect 4 Programming
JavaScript Basics You MUST Know
JavaScript Basics You MUST Know
Permutations & Combinations in Javascript
Permutations & Combinations in Javascript
Javascript window.confirm() method | Javascript tutorial
Javascript window.confirm() method | Javascript tutorial
JavaScript Basics | Chapter 1 📖 | Part 1
JavaScript Basics | Chapter 1 📖 | Part 1

.then() Method

The .then() method is used to handle the fulfilled promise. You provide it a function that will be executed once the promise is fulfilled. The function receives the fulfilled value as an argument.

.catch() Method

The .catch() method is used to handle a rejected promise. It takes a function as an argument, which will be executed if the promise is rejected, receiving the rejection reason as an argument.

These methods are chained, as demonstrated in many examples on W3Schools, allowing you to create complex workflows and enhance code readability and maintainability.

Async/Await with Promises

W3Schools also offers a complete guide on using async/await with promises. These keywords make working with promises even easier, allowing you to write asynchronous code as if it were synchronous.

Async Function

An async function is a function that can contain one or more await expressions, which pause and resume the execution of an async function until a promise is fulfilled or rejected. It always returns a promise.

Using Await with Promises

When you use await with a promise, the async function will pause execution until the promise is fulfilled or rejected. This makes the async function wait for the promise to complete, rather than move on to the next line of code immediately.

W3Schools concludes this part of their tutorial by providing many practical examples of using promises in real-world scenarios, such as fetching data from an API or handling form data.

In closing, promises are a powerful tool in modern JavaScript development. Working with W3Schools' tutorials, you'll grasp the basics and gain the confidence needed to write asynchronous and efficient code. Start practicing and exploring more advanced topics, guided by W3Schools' comprehensive lessons.