DeveloperBreeze

JavaScript Promise Example

// Function that returns a Promise
function customPromise() {
    return new Promise((resolve, reject) => {
        // Simulate asynchronous operation with a setTimeout
        setTimeout(() => {
            // Resolve the promise with a message after 1000 milliseconds
            resolve('Promise resolved!');
        }, 1000);
    });
}

// Call the function and handle the resolved promise
customPromise().then(result => {
    console.log(result); // Output: Promise resolved!
});

Continue Reading

Handpicked posts just for you — based on your current read.

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!