How exactly does document.write() work?
When I do
document.write('<script src="file.js"><\/script>');
inside a script tag which is inside a head tag, document.write() inserts the tag within the head tag. (Since I've called it from within head tag)
When document.write is called after the page fully loads, it implicitly calls document.open() and then executes document.write()
My question is, after page load, when I call
document.write('hello'); //Inserts 'hello' within body tag
and when I call
document.write('<script src="file.js"><\/script>'); //Inserts within head tag
So how exactly does document.write() know what kind of string am I inserting? Does it parse the string too?