document.querySelectorAll(“p”) が返すオブジェクトの型はどれか。
- Array
- HTMLCollection
- NodeList
- Object
正解
- NodeList
解説
querySelectorAll() は NodeList を返す。getElementsByClassName() などは HTMLCollection を返すが、両者は似ていても異なるオブジェクトである。
使用例(サンプルコード)
[ javascript ]
let paragraphs = document.querySelectorAll("p");
console.log(paragraphs instanceof NodeList); // true