What\'s the difference between:
var div = document.createElement(\'div\');//output -> [object HTMLDivElement]
document.getElementById(\'container\').appe
With your JS/DOM engine, calling Element.appendChild with a string as an argument causes a new Text node to be created then added.
Your first example creates a Your second example is equivalent to: As Sarfraz Ahmed mentioned in his answer, you can make the second example work how you want it to work by writing: as its contents.
var div = '';
document.getElementById('container').appendChild(document.createTextNode(div));//output ->
var div = '';
document.getElementById('container').innerHTML = div;