why escaping / in javascript '<\/script>'?

javascript

Solution

- Single and double quoted strings have the same escaping rules.

- It prevents `</script>` from being parsed as an closing tag.

"`</script>` and "`<\/script>`" are the same to JavaScript, but only the first one is interpreted by the HTML parser to contain a HTML closing tag.

Problem

I have seen everyone doing it tho i dont' get why. ``` document.write('<script src="src"><\/script>'); ``` I mean using the single ' you shouldn't need to esacape chars?

Original source

Related problems