What is the real reason we need to escape the slash in a JavaScript string
In an HTML 4 document, the </
sequence within an element defined as containing CDATA (for example, a script) is the end tag and terminates the element (with an error if it is not </script>
.
In relation to JS /
and \/
identical inside the string. As for HTML, </
runs the end tag, but <\/
does not.
and also why should we avoid string / no strings in XHTML.
XHTML does not provide a method for indicating that an element contains embedded CDATA, so you need to explicitly handle characters that would otherwise have special meaning ( <
, &
, etc.). Their wrapper contains an element with CDATA markers - this is the easiest way to achieve this.
Quentin
source share