Comments are used for following in javascript
- To document code. It makes code readable & easier to understand.
- To avoid or stop code execution while debugging a script.
Javascript comments are of two types:
- Single line comment
- Multi line comment
Single line comment
Two forward slashes without space are used to add single line comment, As its name, only single line can be commented.
<script>
// I am single line comment
</script>
Multi line comment
To comment more than one line, javascript allows multiline comment.
<script>
/*
I am
Multi line
comment
*/
</script>