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?

Source: JavaSript – Stack Overflow

November 28, 2021
Category : News
Tags: conditional-statements | forEach | javascript

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.