6

Say, JavaScript is in the middle of executing some method, and I'm pressing a button which has some event handler attached. Will the current method execution get paused and the click event handler start executing right away, or will js finish method execution and only then proceed with executing the click event handler?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Andrey
  • 20,487
  • 26
  • 108
  • 176
  • not 100% related question but a good source http://stackoverflow.com/questions/2734025/is-javascript-guaranteed-to-be-single-threaded – Liviu T. Sep 22 '11 at 20:56

2 Answers2

5

The event will fire after the current Javascript finishes execution, since Javascript is single threaded. This is also why your browser can lock up.

Digital Plane
  • 37,354
  • 7
  • 57
  • 59
2

The currently executing code will continue running until it has returned and then the next event will be run out of the event queue. Will be most likely your mouse click event.

Declan Cook
  • 6,066
  • 2
  • 35
  • 52