Single line comments syntax:
// Single line comment
Multi-line comments syntax:
Comments in code allow you to write notes to yourself about the code you’ve written. The text inside a comment will not show up on the actual web page.
As you can see from the examples above, comments can span a single line or multiple lines.
Disabling code using comments
Comments can also be used to temporarily disable sections of code, so you can see how your web page works without executing certain lines of code. Here’s an example:
// console.log("This statement won't print out to the console when it's in a comment");
VS Code Tip
To quickly create a comment in VS Code, press Ctrl + / on Windows or Cmd + / on macOS. This will create a new comment on a blank line or comment out the line your cursor is on if there is already code on it.
Try the following statements in the console:
// this is a comment