When async is defined as a function expression, you have to invoke the function and store it as an instantiated variable
let paramFromExternalScope = "Something"; const createUser = async () => await someAsyncFunction(paramFromExternalScope); // must be invoked to obtain the value from Promise const createdUser = createUser();
.then
chainThis function won't do anything after execution because there is no return
statement inside the callback function.
// no result return await fetch("url") .then(res => res.text()) .then( result => { JSON.parse(result) } // missing return );
Promise
objectWithout converting the Promise
object to a value
, you won't be able to access the content of the Promise call result.
Promise
object to a value..then()
to access the valuefetch().then(value => console.log(value));
await
inside async
function, then assign the return to a variableconst value = await fetch();
fetch("url") .then((response) => { // missing .json() return response })
fetch("url") .then((response) => { // let is scope-limited let result; result = response; }) // correctly scoped let result; fetch("url") .then((response) => { result = response; })