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

170
Visualizações
Always True if statement doesn't execute

Context: I'm creating a tbody table from a data file, and I'd like to apply a format to certain columns. It works just fine if I leave out the conditional in which I check the column number. In order to rule out other problems in that part of my code, I've stripped it way down. What I still can't figure out is why the always-true if statement just doesn't fire.

Stripping out the superfluous stuff, this code works:

Object.values(dataRow).forEach((val) => {
      let cell = row.append('td');
      cell.text(val);
    }

But this doesn't:

Object.values(dataRow).forEach((val) => {
      if (true) {
        let cell = row.append('td');
      }
      cell.text(val);
    }

To clarify, as long as I don't have the if statement in there, my td cell is populated as I expect it to be. But with the conditional included, nothing happens.

What am I missing? JavaScript isn't my first language, so maybe I'm missing something truly basic?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Should be the same in most languages, but there is something called scope.

If you declare a block-scoped variable within a conditional statement, its value will not be defined outside of it.

For example:

if (true) {
  let a = 9;
  a // 9
}
a // ReferenceError: a is not defined
let a;
a // undefined
if (true) {
  a = 9;
  a // 9
}
a // 9
about 4 years ago · Juan Pablo Isaza 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