Promise Resolve
Predict Output Medium
Question
What does this code print?
Code
Promise.resolve(42).then(x => console.log(x));
Hint
Promise.resolve creates an already-resolved promise.
Explanation
Promise.resolve(42) creates a promise that is immediately resolved with 42. The .then() callback receives 42 as the argument, so it prints 42. This is useful for starting a promise chain or converting a value to a promise.
Related Resources
Related Lessons
- Async JavaScript
Learn async JS.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.