Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What kind of construct would use the comment delimiter */ in a Javascript?

From "Javascript: the Good Parts": the Good Parts:

Avoid /* … */ for comments, */ appears in useful constructs in javascript. Use //.

I'm curious as to what these "useful constructs" might be, as I can't think of any OTOH (except maybe a regex like /.*/?)

like image 645
nneonneo Avatar asked Oct 22 '12 03:10

nneonneo


1 Answers

The blogger was trying to abbreviate what Crockford wrote at JavaScript: The Good Parts, Chapter number 2 ( Grammar ). This topic comes on the last paragraph of the first section ( Whitespace ). It says,

The /* */ form of block comments came from a language called PL/I. PL/I chose those strange pairs as the symbols for comments because they were unlikely to occur in that language’s programs, except perhaps in string literals. In JavaScript, those pairs can also occur in regular expression literals, so block comments are not safe for commenting out blocks of code. For example:

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

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

like image 76
naveen Avatar answered Sep 20 '22 18:09

naveen