-1

I can't figure out why the string "</script>" is giving me the following error:

Uncaught SyntaxError: Invalid or unexpected token

I only see the error when I declare the variable inline HTML. If I declare the variable in the console it doesn't give me any trouble.

I also noticed that "</scrip>" and other letter combinations do not give the error. Is there something special about that string that is causing this? I'm stumped.

<script>
  var thing = "</script>";
</script>

0

1 Answer 1

0

The solution was actually just to escape the slash:

var thing = "<\/script>";

Explanation here: https://stackoverflow.com/a/1479554/3498950

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.