Следите за новинками
в нашем Telegram канале. Жми, чтобы подписаться:)
⊗jsSpAsnEM 152 of 294 menu
◀ ▶

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'); });
← →
↑
English▼
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline