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

245
Vistas
JavaScript for loop, I don't understand

I don't understand the output of this question from CodeAcademy. It is stated in the for loop that X+=1, but why is the output printing the X index 0 for the second time? I thought it would be index 1(A) as X+=1.

const tags = ['G', 'A', 'T',' C'];
for (let x = 0; x < tags.length; x +=1) {
  for(let y = 1; y < tags.length - 1; y +=1) {
    console.log(`${tags[x]}${tags[y]}`,x,y);
  }
}
//output GA  GT  AA  AT  TA  TT  CA  CT

Output:

Console Image

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

0

The inner loop starts with y = 1 and ends with y = 2 for this tags array. That means for each iteration of the outer loop, the console.log runs twice. That's why you are seeing 4 * 2 = 8 outputs printed out, where 4 is the number of iterations the outer loop goes through, and 2 is the number of iterations the inner loop goes through each time.

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