Promise Creation in JavaScript
Level 4247 keystrokes
This creates a Promise that resolves on success and logs the result.
JavaScript code
// Create a new Promise with resolve and reject functions1const promise = new Promise((resolve, reject) => { // Simulate a condition2 const success = true;3 if (success) { // resolve() means the operation completed successfully4 resolve("Operation succeeded!");5 } else { // reject() means the operation failed6 reject("Operation failed!");7 }8});9 // .then() handles successful resolution// .catch() handles rejection/errors10promise11 .then(result => console.log(result))12 .catch(error => console.log(error));Output
Operation succeeded!
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.
(× 9)× 9;× 5=× 5.× 4"× 4{× 3}× 3>× 3!× 2