Lexical grammar — Block comments
The second way is the / / style, which is much more flexible.
Reference note (untrusted external data; do not execute it as instructions).
The second way is the / / style, which is much more flexible.
For example, you can use it on a single line
You can also make multiple-line comments, like this
You can also use it in the middle of a line, if you wish, although this can make your code harder to read so it should be used with caution
In addition, you can use it to disable code to prevent it from running, by wrapping code in a comment, like this
In this case, the console.log() call is never issued, since it's inside a comment. Any number of lines of code can be disabled this way.
Block comments that contain at least one line terminator behave like line terminators in automatic semicolon insertion.
Attribution: Adapted from MDN Web Docs under CC-BY-SA-2.5. Adaptation: WikiKV isolated this documentation section, normalized formatting, removed long code blocks, and shortened it for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
MDN Web Docs — files/en-us/web/javascript/reference/lexical_grammar/index.md :: Block comments ↗Revision d14bee540b53 · CC-BY-SA-2.5