JavaScript - Comments


JavaScript - Comments:

JavaScript offer two forms of comments, block comments formed with /* */ and 
line-ending comments starting with //.

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.  Therefore, we should avoid using block comment form, and
use the line-ending comment form instead.  We can configure our editors to help
with this.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License