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

184
Vistas
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 Respuestas
Responde la pregunta

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 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