What is an HTMLCollection in JavaScript?
A
An array of JSON objects
C
A live collection of HTML elements
Analysis & Theory
`HTMLCollection` is a live collection of HTML elements — it updates when the DOM changes.
What is a NodeList?
A
An array of HTML elements
B
A static or live list of nodes returned by DOM methods
C
A collection of functions
Analysis & Theory
`NodeList` is a collection of nodes. It can be static (e.g., `querySelectorAll`) or live (e.g., `childNodes`).
Which method returns a NodeList?
B
getElementsByClassName()
Analysis & Theory
`querySelectorAll()` returns a static `NodeList` of all matching elements.
Which method returns an HTMLCollection?
C
getElementsByClassName()
Analysis & Theory
`getElementsByClassName()` returns a live `HTMLCollection`.
Can you use `forEach()` on an HTMLCollection directly?
Analysis & Theory
`HTMLCollection` does not support `forEach()` directly — you must convert it to an array first.
Which of the following can be used to loop through a NodeList?
Analysis & Theory
NodeList supports looping using `for`, `for...of`, and `forEach()`.
Which of these changes when the DOM changes?
B
NodeList from querySelectorAll()
Analysis & Theory
Only `HTMLCollection` is live — it reflects changes to the DOM automatically.
How can you convert an HTMLCollection to an array?
Analysis & Theory
Use `Array.from()` or `[...collection]` to convert `HTMLCollection` to an array.
What type of elements does `childNodes` return?
Analysis & Theory
`childNodes` returns a live `NodeList` of all child nodes, including text and comments.
Which of the following is TRUE about HTMLCollection and NodeList?
C
They are not real arrays but are array-like objects
Analysis & Theory
Both `NodeList` and `HTMLCollection` are **array-like objects**, not true arrays.