Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
Does JavaScript have a queue of event listeners that constantly checked if there are any of them?

I am learning JavaScript and I added some JavaScript code on Chrome Dev Tools or JavaScript Console to delay or block clicking any button on a website in a number of seconds. And it worked as expected. However, that click triggered automatically after a couple of seconds. Why might that be? Does JavaScript have a queue of event listeners that constantly checked if there are any of them and act on those events?

function hang(secs) {
    const doneAt = Date.now() + (secs * 1000)
    while (Date.now() < doneAt) {}
}

hang(10)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your while loop will block everything else the browser is doing for the amount of time requested. It's likely to trigger the browser "Script is taking too much time" warning popup. That is not how you implement delays in JavaScript. If you want to delay reaction to user interactions, use the timer mechanisms (setTimeout() etc).

As to your question specifically, events do in fact queue up, but nothing is "constantly checking" them; an event happens, and that simple fact causes an action to be put on the queue. While your CPU-burning loop is running, no event handler dispatches can occur. Once the function finishes, the event handlers will be dispatched. The JavaScript environment is single-threaded.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!