🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: XSS: all 10 questions

Quiz: XSS · Question 7 of 10

Which line in plain JavaScript is safe for showing a user's comment?

Which line in plain JavaScript is safe for showing a user's comment?

  1. A.el.textContent = comment
  2. B.el.innerHTML = comment
  3. C.document.write(comment)
  4. D.el.outerHTML = comment
Answer & explanation

Correct answer: el.textContent = comment

textContent treats the value as text, never as HTML.

Can you get the rest right without peeking?

Take the timed Quiz: XSS quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →