Search code examples
javascript-objectsunexpected-token

Is script tag inside javascript string object currently forbidden?


I try this: let textValue='<script></script>' but I get an error stated

Uncaught SyntaxError: Invalid or unexpected token unexpected token

Unterminated string literal

I am wondering do javascript currently forbid the use of <script> tag for string object.


Solution

  • You can do it like this:

    let textValue='<script>content<\/script>';
    console.log(textValue);