async function timeout(ms) { await new Promise((resolve, reject) => { setTimeout(resolve, ms); }); } async function asyncPrint(str,ms) { await timeout(ms); document.querySelector('body').innerText = str; } asyncPrint('done!', 2000);