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

127
Views
Output for promises and synchronous code is unclear
console.log(1)
const promise = new Promise((resolve) => {
    console.log(2)
    resolve()
    console.log(3)
})

console.log(4)

promise.then(() => {
    console.log(5)
}).then(() => {
    console.log(6)
})
console.log(7);

Output for this block is 1,2,3,4,7,5,6

I do understand that promise callback will go event loop and will run once promise is resolved then how we are getting 2, 3 printed before the promise is resolved. can someone please explain this to me?

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!