Categories

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; }
/**/

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>