Why do I need to escape the '/' character in JavaScript?
javascript
Solution
The problem may be that the web browser sees the "`</script>`" sequence and decides that's the end of the script block.
Another way to fix the problem aside from using an escape sequence like you did is to break it apart into 2 strings that are concatenated:
"<" + "/script>"
The behavior you're seeing isn't a bug n the part of the browser.
Browsers don't "look inside" a script block, they just pass the content to the script engine. The "`</script>`" sequence is how they know they've come to the end of the block, and since the browser doesn't interpret the contents of the block, it has no way to know that it's in the context of a literal string in the script code.
Remember that browsers can support more script languages than just Javascript, even if it's not commonly seen. Internet Explorer supports VBscript (and I think any scripting language that can be run by a windows script host, but I'm not sure about that). And when the ability to have script blocks was put into browsers way back when, no one could be sure that Javascript would end up being so universal.
Problem
What exactly needs to be escaped in javascript strings. Or, more specifically, why does ``` var snaphtml = '<script src="http://seadragon.com/embed/lxe.js?width=auto&height=400px"></script>'; ``` give a syntax error? Escaping the final `<\/script>` seems to fix the syntax error, but this doesn't make sense to me as a javascript beginner.