JavaScript Concurrency: Omitting Promise Values
Welcome to the Omitting Promise Values lesson!
This lesson is shown as static text below. However, it's designed to be used interactively. Click the button below to start!
If a JavaScript function is written using { curly braces }, but doesn't have an explicit
returnstatement, then it will always returnundefined.>
function noReturn() {}noReturn();Result:
undefined
The same goes for
Promise.resolve: if we omit its argument, the promise will fulfill, but it will containundefined.>
Promise.resolve();Async Result:
{fulfilled: undefined}This applies to our
thencallbacks as well. If we don't return a value explicitly, the promise will fulfill withundefined.>
Promise.resolve(5).then(function(n) {/* Do nothing. */});Async Result:
{fulfilled: undefined}Here's a code problem:
This promise is fulfilled with the value
5. Attach athencallback that doesn't return anything. That will create a promise that fulfills withundefined.Promise.resolve(5).then(() => {});Async Result:
- Goal:
{fulfilled: undefined}- Yours:
{fulfilled: undefined}