
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Are HTML comments inside script tags a best practice?
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 −
<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.
- Related Questions & Answers
- what are html tags?\n\n
- HTML Comments
- Best practices for Java comments.
- Where should I put <script> tags in HTML markup?
- How can I remove the (//<![CDATA[ , //]]>) blocks; tags inside a script element in Javascript?
- Are button HTML tags outside of a form valid?
- HTML Deprecated Tags
- How to put comments inside a Python dictionary?
- Best practice to wait for a change with Selenium Webdriver?
- What are the essential tags for an HTML Document?
- Best practice for variable and method naming in Java
- How to put multi-line comments inside a Python dict()?
- What are the most important tags for an HTML Document?
- What are JSP comments?
- What are Comments in JavaScript?
Advertisements