firstChild can be white space
Briefly

The article discusses a common confusion in JavaScript regarding the first child of a section element. While one might expect the first child to be an HTML element (like a <div>), it can actually be a text node representing whitespace. The difference lies in the methods used to access children: .firstChild returns any type of node, including text nodes, while .firstElementChild exclusively returns the first HTML element. This distinction is crucial for accurate DOM manipulation and understanding CSS selectors, which ignore whitespace.
What is the first child of the section here? The <div> is the first child of the <section>, right? Wrong! ... text nodes and get the first actual HTML element...
Read at Frontendmasters
[
|
]