JavaScript Async
<!DOCTYPE html> <html> <body> <h2>Creating a Promise</h2> <script> const task = new Promise((resolve, reject) => { const ok = true; if (ok) { resolve("Task done"); } else { reject(new Error("Task failed")); } }); task .then((result) => console.log(result)) // "Task done" .catch((error) => console.log(error.message)); </script> </body> </html>