My editor (Geany) changes the colour of a comment when a comment starts with /*!
. What's the difference between /* ... */
and /*! ... */
?

- 18,291
- 25
- 109
- 191

- 547
- 5
- 14
3 Answers
The ! prevents YUI compressor from removing the comment when it compresses. (It just removes 1 ! instead. Multiple !'s mean you can compress multiple times without loss of the comment.) It's just an extension, but not part of javascript itself.
Documentation is here. Search for 'C-style comments'.
also, I'm not aware of any other compressors that respect the !. Packer, closure compiler, shrinksafe, and jsmin do not respect it at least.

- 19,417
- 5
- 40
- 40
-
Reference: http://www.julienlecomte.net/yuicompressor/README @Phonethics: This would be handy for copyright statements and such you want left in the code. – T.J. Crowder Jun 10 '10 at 07:19
-
2Microsoft's Ajax Minifier respects the bang as well. – Protector one Nov 09 '11 at 10:48
-
Respect the bang. We must always respect the bang. – Charles Burns Sep 04 '15 at 22:55
-
Link no longer works for: >Documentation is **here** – vitaly-t Dec 29 '15 at 05:47
In Javascript, there is none, they're both just inline comments. Presumably geany is doing special coloring for some documentation tool or similar (edit: apparently it's YUI Compressor, see x1a4's answer) that treats /*!
comments specially (similar to the way JSDoc treats /**
comments specially).

- 1
- 1

- 1,031,962
- 187
- 1,923
- 1,875
They are both treated as comments in JavaScript. For the second one, since the exclamation is inside, JavaScript doesn't care what's inside the comment anyway.
Tools that minimizes or compresses JavaScript files would get rid of anything inside /* ... */, but would leave the second style of comment intact. The reason is so that there's a way to keep the copyright information in the minified or compressed version of JavaScript files.

- 10,579
- 11
- 54
- 80