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

232
Views
Js executes code that is after a for loop before the loop finish

I know that JavaScript executes loops synchronously. So I don't understand why in the code below alert runs before the end of the for loop. I expected js to first complete the loop and then to execute the alert function. Instead, the for loop starts calling the console.log("loop"), and after a couple of seconds the alert gets executed while at the same time the console.log continuous to print the text "loop".

for(let i=0; i<100000; i++){
  console.log("loop");
}

alert("hello world");

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!