Source Code: (back to article)
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<script>
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const doSomething = async() => {
document.write('Wait for 2 seconds!');
await sleep(2000)
document.write('After 2 seconds!');
}
doSomething();
</script>
</body>
</html>