coding180 icon
Coding180
JavaScript - Comments are important

JavaScript - Comments are important

Home > Tutorials > JavaScript > Getting Started


The function of the comment is to improve the readability of the code, to help yourself and others read and understand the JavaScript code you write.

The content of the comment will not be displayed on the web page. 
Comments can be divided into

  • single-line comments
  • multi-line comments.

For the convenience of reading, we generally put the comment content at or around the end of the statement that needs to be explained.

For single-line comments, add the symbol "//" before the content of the comment.

<script type="text/javascript">
  document.write("Single-line comments use '//'"); 
// I am a single line comment
</script>

Multi-line comments start with /* and end with */

<script type="text/javascript">
   document.write("Multi-line comments use /*comment content*/");
   /*
    multiline comment
    Develop a good habit of writing notes
   */
</script>

 

Task - Exercise - 6

1. Use the symbol // to turn document.write("hello") to a single line comment.

2. Use /* and */ to turn the text content of lines 8, 9, and 10 into comments

Task Code

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hidden comments</title>
 <script type="text/javascript">
    document.write("Hello");
    do you know
    JS can achieve many dynamic effects
    Come and learn!
 </script>
</head>
<body>
</body>
</html>

 


user

Robort Gabriel

Lagos, Nigeria

Freelance Web Developer, Native Android Developer, and Coding Tutor.

Skills
  • UI / UX
  • JavaScript
  • Python
  • PHP
  • Kotlin
  • Java
  • Bootrap
  • Android
  • Laravel