BugHunt

[object Promise] in output

A promise was used where its resolved value was expected — nearly always a missing await.

JavaScriptAsync and race conditions

What it means

An async function always returns a promise. Using that promise in a string or a calculation converts it via toString, giving [object Promise]. The count or shape often looks right, which is why it slips through.

Common causes

1. Missing await

The promise itself flows onward instead of the value.

Breaks

const total = getTotal();
console.log(`Total: ${total}`);

Works

const total = await getTotal();
console.log(`Total: ${total}`);

2. map with an async callback

map gives an array of promises. The length is right, which is the trap.

Breaks

const names = ids.map(async id => fetchName(id));

Works

const names = await Promise.all(ids.map(id => fetchName(id)));

3. reduce with an async callback

The accumulator is a promise from the second iteration onward.

Breaks

nums.reduce(async (acc, n) => acc + await f(n), 0);

Works

nums.reduce(async (acc, n) => (await acc) + await f(n), Promise.resolve(0));

How to find it in your own code

If you see [object Promise], or typeof gives 'object' where you expected a number or string, look for the await you dropped. Promise.all is what you want whenever you need every result rather than the first.

Still not sure why yours breaks?

Paste it into the visualizer and watch it run line by line, with every variable at every step. Free, and it runs in your browser.

Other common errors