Event model asynchrony in JavaScript

You know that using the addEventListener method, you can subscribe to various events that occur on page elements. For example, let's subscribe to a click on some element, the reference to which is stored in the variable elem:

elem.addEventListener('click', function() { console.log('1'); }); console.log('2');

In the above code, the second output to the console will be executed first. When will the first one be done? Once upon a time: execution of this code waits for an event to occur - a click on an element. As soon as this happens, our code will be executed.

Tell me in what order the numbers will be displayed in the console:

elem1.addEventListener('click', function() { console.log('1'); }); elem2.addEventListener('click', function() { console.log('2'); });
enru