1setTimeout(function(){
2 console.log("hello");
3}, 3000); //wait for atleast 3 seconds before console logging
1console.log('hello');
2setTimeout(() => {
3 console.log('async message that appears on the screen in 1 second')
4}, 1000);
5console.log('world');
6
7// hello
8// world
9// async message that appears on the screen in 1 second
1// wait 1000ms and then run func()
2let myTimeout = setTimeout(func, 1000);
3// cancel the timeout
4clearTimeout(myTimeout);
1function doHomeWork(subject, callback){
2 setTimeout(callback,500);
3 console.log("doing my homework:", subject)
4}
5
6doHomeWork("Maths", function(){console.log("finished my homework");});
7