Promise Basic in JavaScript
Level 4170 keystrokes
Promises handle asynchronous operations, resolving with a value or rejecting with an error.
JavaScript code
// Create a new Promise// The executor function receives resolve and reject callbacks1const promise = new Promise((resolve, reject) => { // setTimeout simulates an async operation // After 100ms, resolve with "Success!"2 setTimeout(() => resolve("Success!"), 100);3});// .then() handles the resolved value// This callback runs when the promise resolves4promise.then(result => console.log(result));// This runs immediately (before promise resolves)5console.log("Waiting...");Output
Waiting... Success!
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this JavaScript code and how often they appear.
(× 8)× 8.× 6;× 4"× 4=× 4>× 3,× 2!× 1{× 1