title: Replace NaN with "-" character using JavaScript
body: <p>Can you please tell me how to replace NaN with another character?</p>
  <p>There are variables that are assigned some numeric value.</p>
  <p>Further, in the function, these variables get their values, which I then display in the html table. But, sometimes some variable (let it be the variable &quot;d&quot;) - returns NaN.</p>
  <p>To fix this, I separately created an array with variables that already have some values.</p>
  <p>Next, I started the iteration loop. If the condition returns NaN, then it should be replaced with &quot;-&quot;. But, it doesn't work.</p>
  <p><strong>UPD</strong> Most likely, I did not correctly make it clear why I created the array. I created an array in order to iterate over all the variables that I have, and if any variable has NaN (null, undefined), then it will be assigned the value &quot;-&quot;.</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var a, b, c, d, x1, x2, x3, x4;
  var elem = document.getElementById.bind(document);
  
  function iFunc () {
    a = 1;
    b = 3;
    c = 2;
    d = NaN;
    
    x1 = elem('a1').innerHTML = a;
    x2 = elem('b1').innerHTML = b;
    x3 = elem('c1').innerHTML = c;
    x4 = elem('d1').innerHTML = d;
    
    var arrX = [x1, x2, x3, x4];
    
    for (var x of arrX) {
      if (x !== x) {
      x = "-"; // the character that was supposed to replace NaN
      console.log(x);
    }
   }
  }
  
  iFunc ();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;table&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;span id="a1"&gt;&lt;/span&gt;&lt;/td&gt;
      &lt;td&gt;&lt;span id="b1"&gt;&lt;/span&gt;&lt;/td&gt;
      &lt;td&gt;&lt;span id="c1"&gt;&lt;/span&gt;&lt;/td&gt;
      &lt;td&gt;&lt;span id="d1"&gt;&lt;/span&gt;&lt;/td&gt;
    &lt;/tr&gt;
   &lt;/table&gt;</code></pre>
  </div>
  </div>
  </p>