in a comment break the parser? [duplicate]", "text": "<p>Why does adding <code></script></code> in a comment break the parser? Is this a bug or is there something in the documentation I've overlooked?</p> <p>I've tested this in Chrome, Firefox, Opera, Internet Explorer and they all produce the same result.</p> <p><strong>Single-line comment:</strong></p> <p></p> <div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="prettyprint snippet-code-js lang-js prettyprint-override"><code>function Foo(){ // </script> alert("bar"); }; Foo();</code></pre> </div> </div> <p><strong>Multi-line comment:</strong></p> <p></p> <div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false"> <div class="snippet-code"> <pre class="prettyprint snippet-code-js lang-js prettyprint-override"><code>function Foo(){ /* </script> */ alert("bar"); }; Foo();</code></pre> </div> </div>", "answerCount": 1, "upvoteCount": 419, "dateCreated": "2015-09-30 07:25:01", "dateModified": "2022-09-30 18:43:19", "author": { "type": "Person", "name": "Bjørn-Roger Kringsjå" }, "acceptedAnswer": { "@type": "Answer", "text": "<p>This happens because HTML parser as defined by W3C is totally separated from the JavaScript parser. After the <code><script></code> tag it looks for the closing <code></script></code>, regardless that it's inside comments or strings, because it treats JS code as normal text.</p>", "upvoteCount": 184, "url": "https://exchangetuts.com/why-does-adding-script-in-a-comment-break-the-parser-duplicate-1639543148183288#answer-1646917068848639", "dateCreated": "2022-09-30 06:43:19", "dateModified": "2022-09-30 18:43:19", "author": { "type": "Person", "name": "mck89" } } } }