Search code examples
javascriptsyntaxcommentstheory

How is a comment categorized in JS?


In JavaScript syntax, we know of stuff like:

  • +, =, ,, (...) being operators
  • var, let, function, for being keywords
  • 1, "string", being literals
  • 1+1 being an expression containing operators and literals and

  • var myVar = 1+1; being a statement containing keywords and expressions

How would you group // and /* ... */? I feel like it is an operator, but I don't see it in the Operator precedence table

I will soon give a training for beginners in JavaScript and I would like to be as rigorous as I can


Solution

  • Comments are their own category, and a very high-level syntax production. You can see this in the lexical structure overview in the specification, and in the section on comments.