Fluid output · Question 12 of 12

A template writes <script>var name = "{user.name}";</script>. Which assessment is correct?

1 answer is correct. Hard

Show answer

Answer

  • D HTML escaping does not suit JavaScript; better JSON or a data attribute

Explanation

htmlspecialchars() is meant for HTML, not for JavaScript strings. Pass values cleanly as a data attribute or JSON-encoded and read them in the script.

Certifications & exams

Which exam comes next?

You can already practise for 19 exams, and 21 are up for a vote. See all certifications with their official information, cast your vote or suggest your exam.

See all certifications