次のうち、コメントを表すノードはどれですか?
- Commentノード
- Textノード
- Attributeノード
- Elementノード
正解
- Commentノード
解説
Commentノードは、HTML/XML文書内のコメント(例: <!-- コメント -->)を表します。
使用例(サンプルコード)
[ javascript ]
// コメントノードを取得
let comments = [...document.childNodes].filter(n => n.nodeType === Node.COMMENT_NODE);
console.log(comments);