Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!