title: Why does JavaScript sometimes convert null to empty string and sometimes to "null" string?
body: <p>I'm studying JavaScript and I'm confused about the following:</p>
  
  <pre><code>document.getElementById("demo").innerHTML = typeof (document.getElementById("demo").innerHTML);
  </code></pre>
  
  <p>It assigns "string" to an HTML element. OK. So then I suppose when I will try to assign some value of different type (not string) it will be converted to string first:</p>
  
  <pre><code>document.getElementById("demo").innerHTML = null; //null will be converted to string first
  </code></pre>
  
  <p>like this:</p>
  
  <pre><code>document.getElementById("demo").innerHTML = String(null);
  </code></pre>
  
  <p>HTML element gets en empty value in the first example. But the second example returns "string". Why? This tutorial <a href="http://www.w3schools.com/js/js_type_conversion.asp" rel="nofollow">http://www.w3schools.com/js/js_type_conversion.asp</a> says that String(null) returns "null", but not empty string. As I see it's true only for the second example.</p>
  
  <p>How to understand this confusing conversion behavior of JavaScript? Why doesn't the first example return "string"?</p>
  
  <p><strong>Edited:</strong></p>
  
  <p>Now partially I understood it.
  JS uses <code>toString()</code> but not <code>String()</code>. And <code>toString()</code> returns empty string for null.
  So now my question is: Why <code>toString()</code> and <code>String()</code> produce different values?</p>
  
  <p><strong>Edited 2:</strong></p>
  
  <p>Examples:</p>
  
  <pre><code>document.getElementById("demo").innerHTML = String(null); //returns an empty string 
  document.getElementById("demo").innerHTML = null.toString(); //returns "null" string
  </code></pre>