Example 1 — Inspect document.children
Log length, first tag name, and collection type (MDN pattern).
console.log(document.children.length); // 1
console.log(document.children[0].tagName); // "HTML"
console.log(document.children.constructor.name); // "HTMLCollection" How It Works
- Read the collection.
document.childrenis a liveHTMLCollection. - Check length. Typical HTML documents report
1. - Inspect the child. Index
0is usually the<html>root. - Confirm the type.
constructor.nameshowsHTMLCollection.

