Why do I get an error message when I print console.log ('< / script >') in my code? It is no problem to type in the console.

1, why is there an error in printing console.log ("< / script >") in the code, while typing it directly in the console will not report an error?
2, print the console.log ("< / script >") code in the code, and the console output is normal?
ask for advice.

Mar.28,2021

Please take a look at this screenshot:

clipboard.png


:

  • JSscript
  • <script></script>

: console.log('\<\/script>')




you may understand when you see the rendering.


because this is the code in the html file.
your html file is first parsed by the browser's html parsing engine. You know, the file itself is just a sequence of strings, and the dom structure will come out only after parsing.

if you give a string '< script > console.log ('< / script >') < / script >', it is parsed to < script > console.log (the tag'< / script > and ') < / script > .

the previous one is the script element, so the browser will pass the content between the tags to the js engine for parsing and execution, obviously, the content is a syntax error.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b327c0-2be2f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b327c0-2be2f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?