title: js - Comparison with 0 always returns true?
body: <p>I'm just printing a rectangle to the console to get somewhat familiar with JS. I have a nested loop (pseudocode <code>for i &lt; this.height</code>, <code>for j &lt; this.width</code>). If j is 0 or width - 1, I'd like to print out a <code>|</code> for the border:</p>
  <pre class="lang-js prettyprint-override"><code>if (j == this.width - 1 || j == 0)
  { c = '|'; }
  </code></pre>
  <p>and then <code>c</code> is appended to my output. The comparison to  <code>0</code> returns true regardless of the <code>j</code> value. My best guess is that it doesn't think that 0 is the type that is, or I've used it in some way that JS thinks it's a wildcard. For reference, my output looks like this:</p>
  <pre><code>--------
  ||||||||
  ||||||||
  ||||||||
  ||||||||
  ||||||||
  ||||||||
  --------
  </code></pre>
  <p>The -'s at the top and bottom are specified in the outer loop.</p>
  <h3>Minimal Reproducible Example</h3>
  <p>Agh, sorry I forgot this. Here's the code for the function:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let obj =
    {'width': 8
    ,'height': 8  
    ,'ascii_display' : function() {
        let output_str = "";
        for (let i = 0; i &lt; this.height; i++) {
          let c = ' ';
  
          /* inner loop will not override these */
          if (i == 0 || i == this.height - 1) {
            c = '-'; 
          }
  
          for (let j = 0; j &lt; this.width; j++) {
            if (c == " ") {
              if (j == this.width - 1 || j == 0) {
                c = '|'; 
              }
            }
            output_str += c;
          }
          output_str += "\n";
        }
        console.log(output_str);
        }
    };
    
  obj.ascii_display();</code></pre>
  </div>
  </div>
  </p>