When using it in a string </script>
, please note that the browser will report an error. The
browser will report the following error:
Uncaught SyntaxError: Invalid or unexpected token
Because according to the rules of parsing embedded code, when the browser encounters the string " </script>
", it will consider it to be the closing </script>
tag.
This problem can be solved by using escape characters, for example:
console.log("<\/script>");