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 ...>
   JavaScript code


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

Live Demo

            document.write("Hello World!")

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.

Updated on 12-Mar-2020 11:34:56