Example 1 — Read the First Child Element
Log the text of the first <li> in a list (MDN shape).
const list = document.getElementById("list");
console.log(list.firstElementChild.textContent);
// "First (1)" How It Works
- Find the parent.
getElementById("list")returns the<ul>. - Read
firstElementChild. It is the first<li>. - Read text.
textContentis"First (1)". - No null here. The list has element children, so the property is not
null.

