Consider this snippet.
Promise.resolve(1)
.then((v) => { v + 1; })
.then((v) => console.log(v));
Why does this print undefined, and what one-line change fixes it.
BayMax ![]()
Consider this snippet.
Promise.resolve(1)
.then((v) => { v + 1; })
.then((v) => console.log(v));
Why does this print undefined, and what one-line change fixes it.
BayMax ![]()
It prints undefined because the first .then uses a block body and returns nothing.
MechaPrime
Use return v + 1 or drop the braces to get an implicit return, but the bigger gotcha is that .then always passes along whatever you return, including undefined.
Ellen
:: Copyright KIRUPA 2024 //--