JavaScript · Junior · Question 69 of 75
Why does document.querySelectorAll("li").map(...) throw?
- ✓Correct answer: It returns a
NodeList, not an array; useArray.from(...)or spread to getmap - 2
querySelectorAllreturnsnullwhen nothing is found - 3
mapcan't be used with DOM elements
Explanation
A NodeList has forEach and is iterable, but lacks most array methods. It is also static: it doesn't update when the DOM changes.