What is the output of the following code? “`js console.log(1); setTimeout(() => console.log(2), 0); console.log(3); “`

JavaScript Associate Medium

JavaScript Associate — Medium

What is the output of the following code? “`js console.log(1); setTimeout(() => console.log(2), 0); console.log(3); “`

Key points

  • `setTimeout` delays the execution of the function passed to it
  • The delay of 0 milliseconds doesn't mean immediate execution
  • JavaScript executes code synchronously unless specified otherwise

Ready to go further?

Related questions