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

250
Vistas
What is this variable referring to in typescript?

So what I am doing is trying to understand what const [,] or const [_,,,] does in this for of loop in typescript or javascript. What are these?

function getArr() {
    return ['a','b', 'c']
}

for (const [,] of getArr()) {
}

for (const [_,,,] of getArr()) {
}
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

In your example both for loops will cause an errors. What you want in JS is called Destructuring assignment. For example you have a function getArr() which returns an array, but you want to get (for some reason) only first array value. You can use Destrictuing Assignment.

const [first, ...rest] = getArr();
console.log(first) // Will output: 'a'
console.log(rest) // Will output: ['b', 'c']

In your example, in the first loop you're trying to use Destructing Assignment on and variable, not an array, so error will happen. Just look how for...of loop works with arrays. Obviously in the second for..of loop you trying to do the same, but saving first array element in the variable by the name _.

about 4 years ago · Santiago Trujillo Denunciar

0

function getArr() {
return ['a','b', 'c']
}



for (const item of getArr()) {
  console.log(item)
}

Try above code if you access return value from the function

about 4 years ago · Santiago Trujillo 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