Q:

Document Html what it is really document in javascript

I have code html code:
<!DOCTYPE html>
<html><head></head><body><script src="index.js"></script></body></html>

And javascript code in index.js:
console.log(document)// HTMLDocument
console.log(document.childNodes[0])//Object DocumentType

but when i delete Doctype in html code and i run         console.log(document.childNodes[0]) i get HTML elements
What does it all mean? Why document have childNodes?
what it is really document in javascript?

A:

document.childNodes[0] is the first element of the page. If there is the <!DOCTYPE html>, then this is the first element, thus it returns DocumentType.
If the DOCTYPE is not there, then the first element is the <html> tag. Thus document.childNodes[0] is the elements of the page, because the all the other tags are included in the html tag (but nothing is included in the DOCTYPE tag)

