// 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!
});JavaScript Promise Example
Related Posts
More content you might like
Code
json python
Python Code Snippet: Simple RESTful API with FastAPI
No preview available for this content.
Aug 04, 2024
Read More Code
javascript
Fetch JSON Data from API in JavaScript
No preview available for this content.
Jan 26, 2024
Read More Code
javascript
Asynchronous Fetch in JavaScript using async/await
No preview available for this content.
Jan 26, 2024
Read More Code
javascript
Asynchronous Data Fetching in JavaScript using 'fetch'
No preview available for this content.
Jan 26, 2024
Read MoreDiscussion 0
Please sign in to join the discussion.
No comments yet. Be the first to share your thoughts!