Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda