Tag written in quotes var str = "</script>"; closes an HTML tag. How to fix?

 <script> "use strict"; var str = "</script>"; document.body.innerHTML = str; </script> 

    1 answer 1

    </script>

    will mean closing the tag no matter where you apply it. To insert it into a string, use

     <\/script> 
    • 2
      Another way, though it is “more expensive”, is to use concatenation: '<' + '/script>' ( jsfiddle.net/yvbt096q ). - Roman Grinyov