Consume promises using .then() for success and .catch() for error handling.
JavaScript Tutorial
JavaScript Tutorial
JavaScript Asynchronous
JavaScript HTML DOM
Advertisement
Google AdSense Slot (LEADERBOARD)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Promises
8 min read
•
Chapter 18 of 22
JS Promises
A Promise is a JavaScript object that links producing code and consuming code: pending, fulfilled, or rejected.
Example
<!DOCTYPE html>
<html>
<body style="font-family:monospace;padding:20px;">
<script>
const myPromise = new Promise((resolve) => setTimeout(() => resolve("Promise Resolved!"), 1000));
myPromise.then(res => document.write(res));
</script>
</body>
</html>
Try it Yourself >>
Opens live sandboxed code editor
Advertisement
Google AdSense Slot (IN-ARTICLE)
Automated High-CTR Ad Rail • Set Publisher ID in config/adsense.php
Community Q&A & Discussion
Verified
No questions yet. Be the first to start the discussion!