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

233
Views
Function declaration inside block scope overriding another function declaration

Can someone explain why first function is running not the second one when I call it?

{
  function a() {
     console.log('first function')
  }
}

function a() {
     console.log('second function')
}

a()

If we declare them in a global scope they behave as expected, but inside block scope it's completely different. Why?

function a() {
     console.log('first function')
}

function a() {
     console.log('second function')
}

a()

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The global function delaration move the function to top (hoisting), the one in the block stays at place.

The below result is from Edge 103.0.1264.37.

a(); // second

{
  function a() {
     console.log('first function')
  }
}

a(); // first

function a() {
     console.log('second function')
}

a(); // first

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!