Are comments 100% safe in all major environments?

Are comments literally simply removed from your source prior to parsing, or can they be considered line-breaks and break continuity in certain contexts?

'foo'.replace(/f/, 'b') //f->b
     .replace(/o/, 'a') //o->a
     .replace(/o/, 'r') /*o->r*/ ;

'foo'.replace(/x/, /*matches "x"*/ 'y');

var foo = ( true !== false ) ? // bikeshed
          'bar' : /*if they're equal, which they won't be, we'll want 'baz'*/ 'baz';

You know, because they say that the spaces are “safe” and “insignificant” or something else, but we all know that there are exceptions. Are comments really safe?

+5
source share
2 answers

They are ignored during parsing; if they were deleted before parsing, the parser will need to double-check the input.

, LineTerminator ; . , ,

ES5 .

, .

+5

, .

( , HTML minifiers, , JavaScript, . , //, script.)

+3

All Articles