Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda