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

107
Vistas
Question about syntax in JS I did not understand - for loop and set time out

for loop and setTimeout with VAR

The Code is:

for (var i = 0; i < 5; i++) {
  setTimeout(() => {
    console.log('The index of this number is: ' + i);
  }, 0);
}

And the output is 5 times the line

The index of this number is: 5

for loop and setTimeout with LET

The Code is:

for (let i = 0; i < 5; i++) {
  setTimeout(() => {
    console.log('The index of this number is: ' + i);
  }, 0);
}

The output is:

The index of this number is: 1
The index of this number is: 2
The index of this number is: 3
The index of this number is: 4
The index of this number is: 5

Why the output is different ? Why does this work like this ?

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