How can i create a promise in javascript?

A promise in JavaScript represents a value that might not be available yet. It can be in one of three states: pending, fulfilled, or rejected. Example:

let myPromise = new Promise((resolve, reject) => {
    setTimeout(() => {
        resolve('Promise resolved');
    }, 2000);
});

myPromise.then(value => console.log(value));
The promise is resolved after 2 seconds, and its value is then logged.

Beginner's Guide to JavaScript