Advantages of Comments
- Comments are useful to display information about the code this makes the code easy to understand for the user. We can use comments to write brief description about the code.
- We can avoid unnecessary code that we use for temporary purpose. Very often we write code that is for temporary purpose we do not need that in actual execution but we implement temporary logic. In such scenario we can comment that code to skip it from actual execution.
- Single Line Comments
- Multiline Comments
Single Line Comments
<script> //This is single line comment. alert("JS Single Line Comment"); // Alerts a message. </script>
Multiline Line Comments
We can write multi line comments using forward slash with asterisk at the start and asterisk with forward slash at the end.
We can also write single line comment using syntax of multiline comment. See below example.
<script> /* This is single Line comment */ /* This is a multiline comment to explain the code */ </script>