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

266
Vistas
JavaScript - What is the difference between declaring a iteration variable using a let versus a var keyword inside a for-loop?

What is the difference between using a let in the body of the for loop and a var specifically in the body of a JavaScript for loop? Do they work differently and why?

Example:

Using let

for (let i = 0; i < 10; i++) {

}

Using var

for (var i = 0; i < 10; i++) {

}

Do these work the same way or differently behind the scenes, does one actually functions better?

Does this difference apply to a while loop and a do-while loop too?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

let is block scoped and var is not. With let, you cannot use i outside the forloop body. With var (function scoped or globally scoped) you can.

for (var j = 0; j < 10; j++) {

}

console.log(j);


for (let i = 0; i < 10; i++) {

}

console.log(i);

You can run the for loop with var in your chrome console, and will see that i has been attached to the window object.

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