Single-line Comment

To write a single line comment in JavaScript, start the comment with a double forward slash //, and write the comment (verbose text) followed by it.

In the following example, we have a single-line comment before the function definition, and another single-line comment after the alert() statement.

</>
Copy
//this is a single line comment
function printMsg() {
    alert("Hello World"); //this is also a single-line comment
}

Conclusion

In this JavaScript Tutorial, we learned how to write single-line comments in JavaScript.