You will need to use
async function first() {
console.log('1a', val);
await second();
console.log('1b', val);
}
async function second() {
console.log('2a', val);
await third();
console.log('2b', val);
}
to bind the logs bafter asynchronously executing the called functions.
And it's the same for
console.log('0a', val);
first();
console.log('0b', val);
, await , aync function. async , , - , , await. 0b wait,
console.log('0a', val);
first().then(function() {
console.log('0b', val);
}, function(err) {
console.error(err);
});
(async function() {
try {
console.log('0a', val);
first();
console.log('0b', val);
} catch(err) {
console.log(err);
}
}());