Neat Little Comment Trick

Hopefully this post will save someone else a bit of time just like it did for me... I stumbled across a trick for commenting out various blocks of code (typically used for debugging). By using a combination of the multi-line and single line comments, you can quickly comment/uncomment code.

/*
alert('error');
//*/

By setting up your comments like this, you can then add another forward slash to the first line to quickly uncomment the alert.

//*
alert('error');
//*/

In SQL, just replace the // on line three with -- and the first two characters on line one should be --. Basically, it should look like this.

--/*
select * from table
--*/

Update (11 May 2010)

I figured out a way to use this trick for CSS even though there is no such thing as a single line comment in CSS. You just need to place an asterisk at the end of the top part of the comment, like below:

/* Comment trick for CSS *
body { background: #000; }
/**/

And then to "activate" the commented code out, just finish closing the upper comment:

/* Comment trick for CSS */
body { background: #000; }
/**/

Did you like what you just read?

Get updates sent directly to your inbox.

Corey Docken

Corey Docken

Corey is a designer and developer with over 10 years of experience building websites. He currently lives in southeastern Minnesota in a small town outside of Winona, MN.

Published on Tuesday, February 23rd, 2010 at 5:48 PM.
Last updated on Thursday, February 12th, 2015 at 5:49 PM.