What construct will use comment separator * / in Javascript?

From "Javascript: Good Details": Good Parts :

Avoid /* โ€ฆ */ for comments, */ appears in useful constructs in javascript. Use // .

I am curious what these โ€œuseful constructsโ€ may be, since I cannot imagine any OTOH (except maybe a regular expression like /.*/ ?)

+6
source share
2 answers

The blogger was trying to shorten what Crockford wrote in JavaScript: โ€œGood Details,โ€ Chapter 2 (Grammar). This topic belongs to the last paragraph of the first section (Whitespace). It says:

The comment comment form for blocks from / * * / came from a language called PL / I. PL / I chose these strange pairs as characters for comments because they are unlikely to appear in these language programs, except, perhaps, in string literals. In JavaScript, these pairs can also occur in regular expression literals, so block comments are not safe for code block comments. For instance:

  /* var rm_a = /a*/.match(s); */ 

causes a syntax error. Therefore, it is recommended that / * * / comments be avoided and // comments. In this book, // will be used exclusively.

+2
source

Yes, regular expressions most likely mean what he meant.

+2
source

All Articles