Async Await
Predict Output Easy
Question
What does this test code print?
Code
test("async", async () => {
const fn = async () => 42;
const result = await fn();
expect(result).toBe(42);
});
// Result?
Hint
async function returns 42, await gets it.
Explanation
The async function fn returns a promise resolving to 42. await fn() unwraps the promise, giving 42. expect(42).toBe(42) passes.
Related Resources
Related Lessons
- Async Testing
Learn async tests.
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.