Are HTML comments inside script tags a best practice?

HTMLWeb DevelopmentFront End Technology

JavaScript can be implemented using JavaScript statements that are placed within the <script>... </script>

</script>.
   <script ...>
   JavaScript code
</script>

Example

HTML comment is added in the <script> tag, which is optional −

Live Demo

<html>
   <body>
      <script>
         <!--
            document.write("Hello World!")
         //-->
      </script>
   </body>
</html>

Added an optional HTML comment above that surrounds our JavaScript code. Yes, it is considered as a best practice, since this is to save our code from a browser that does not support JavaScript.

The comment ends with a "//-->". Here "//" signifies a comment in JavaScript, so we add that to prevent a browser from reading the end of the HTML comment as a piece of JavaScript code.

raja
Published on 23-Apr-2018 13:04:35
Advertisements