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

213
Views
setInterval() doesn't work if a forever loop exists

Overview: (Skip if you want) I have basic knowledge of Javascript, I usually use javascript using node.js to code discord bots. As discord users know, discord already has bots for almost EVERYTHING. I needed some special ideas so I just decided to play around some javascript features and frameworks, hoping to get some ideas from it.

Problem: I discovered a function called setInterval(function, time), I was testing / playing with this function until I discovered something, here is my code:

console.log(`Starting interval with id: ${setInterval(() => {
    console.log(`I at this time is ${i}`)
}, [500])}`);

let i = 0;
for(;;++i);

I was expecting this to work but sadly it didn't. The variable i successfully gets incremented but the callback of setInterval() is never called.

My theory is that the processor is busy due to the high speed of the for(;;++i) so the callback doesn't get time to execute.

I tried to search about this on google, but I didn't know what to search, I even tried searching it on stack overflow but couldn't find anything.

I dont't know if this is a real question, neither do I know if this has a fix, but could someone at least tell me why this problem is occuring, am I right with my theory above?

about 4 years ago · Juan Pablo Isaza
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!