Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

setTimeout - delayed execution

  • setTimeout

Delayed execution, callback function.

  • First we use setTimeout to schedule an anonymous function to be executed 1000 ms later.
  • Then we print "hello" to the console.
  • Then, after a second, the functions starts running and prints "world"
setTimeout(function() {
    console.log("world");
}, 1000);
console.log("hello");
$ node examples/basic/with_timeout.js
hello
world