Also, you wrote
Once a promise is fulfilled, calling “then” on the promise will yield its value.
then(callback) on a promise is analogous to make the callback a listener that waits for the resolved value. It does not “yield” this resolved value — it would be like saying that a listener yields its own argument.
The value of the promise is computed irrespective of any subsequent
then on it. The callback in
then uses that value, but it does not yield it. When exactly will be available the value depends only on the code that computes the promise. The question is somehow irrelevant, because it is an asynchronous computation — we need a callback to use the value, but we can see side effects of the computation on the console. If there is no
setTimeout delay or any form of delay, it will be computed immediately — a subsequent method
then is not required. This is true in an executor (in
new Promise(executor) ) , in an async function or in a callback passed to
p.then . In the latter case, it will be executed immediately after
p is resolved.
The callback “uses” the value to compute a new promise and perhaps have side effects. Perhaps you meant that these side effects, say writing the value on the console, correspond to yielding the value.