Question about event execution in javascript

Let's say javascript is in the middle of executing a method, and I click on a button with an attached event handler. Will the execution of the current method be paused, and the click event handler will immediately start executing or execute the js method and only after that will continue to execute the click event handler?

+6
source share
2 answers

The event will fire after the current Javascript completes execution, as Javascript is single-threaded. This is why your browser may be blocked.

+5
source

The current executable code will continue to run until it returns, and then the next event will be fired from the event queue. Most likely this is a mouse event.

+2
source

Source: https://habr.com/ru/post/897864/


All Articles