In your example, the script tag ends on the fourth line at the first </script
. Everything after that is not within the script tag. The HTML syntax handles this correctly, according to the standard parsing rules defined in the HTML spec and implemented in browsers. There are some cases where the HTML syntax may not handle script tags exactly correctly, but this is not one of them.
To prevent this, don’t include the text </script
inside a script tag. For instance:
<span>
<script>
var a = 10;
var oops = '<'+'/script>';
var b = 12;
</script>
</span>