function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } async function demo() { console.log('Taking a break for 2 seconds...'); await sleep(2000); console.log('2 seconds later'); } demo();