blade-sensei / learning

Roadmap for software engineer, sandbox, algorithms training, it also contains my daily task dashboard
9 stars 2 forks source link

Is the code under and await instruction pending even if in the code under we don't use the value returner by await ? #31

Closed blade-sensei closed 4 years ago

blade-sensei commented 4 years ago

We want to know if the the code under await SO here

console.log('i don't use users');
return 'loading..';

will we executed immediatly ? and in this case console.log('i don't use users') should be displayed before ('waiting..');

OR if this code will we executed pending.

async function load() {
 const users = fakeRequestUserAsync();
 console.log('i don't use users');
return 'loading..';
}

load();
console.log('waiting...');

The response here that the code under await is considered as the callback/then anyway so it's 'pending code' here the output will be

waiting..
i don' use users