title: Document.createElement() vs Document.createTextNode() - Javascript
body: <p>I'm trying to figure out what is the differences between this two:</p>
  
  <pre><code>// first one
  var h1 = document.createElement('h1');
  var t = document.createTextNode('hey');
  h1.appendChild(t);
  document.body.appendChild(h1);
  
  // second one
  document.body.appendChild(document.createElement('h1').appendChild(document.createTextNode('hey')));
  </code></pre>
  
  <p>The first (<a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement" rel="nofollow noreferrer">Document.createElement()</a>) works perfectly, but the second (<a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/createTextNode" rel="nofollow noreferrer">Document.createTextNode()</a>) does not.</p>