Arthur Tarasov
Arthur Tarasov

Reputation: 3791

How to comment out a block of code that already has multiple line comments?

Is there a way to do something like this in Javascript?

/*
    code
    /* Multiple
    line
    comment */
    more code
*/

When I test, I often need to comment out large chunks of code that already have multiline comments.

Upvotes: 9

Views: 23779

Answers (5)

arkan
arkan

Reputation: 663

Alright, comments are for comments don't try to disable large chunks of code with it.

Since we don't have macro like in C, instead use tricks like this:

if(false){ // Disable code
    ...
}
function disabledCode(){
    ...
};

// re-enable code: 
disabledCode();

Upvotes: 1

ryder
ryder

Reputation: 41

This is not a direct answer, per-se. But the fact that block comments can't also block nested comments is a horrifically lame situation to begin with. The answer is to fix JS.

The obvious rule: EVERYTHING between the comment tags is to be treated as a comment. Period. To re-interpret commented text as functional in any way is just not sane. Commented text should not have any functional symbology.... it should not be getting parsed at all.... no excuses. Commented text should be absolutely dead. Non-funcitonal.

Upvotes: 4

ReallyImOneOh
ReallyImOneOh

Reputation: 31

In VS studio I was able to highlight the lines of code and use 'ctrl + /' and it toggles the lines of code to either be commented out or back in. Hope this helps!

Upvotes: 1

Diansheng
Diansheng

Reputation: 1141

I would recommend use block editing feature in text editor. For example, in notepad++, you hold alt key to select the first position of each line, then type "//". you will find the "//" will appear in every line that you have selected.

It shouldn't cost your more than 10secs

Upvotes: 0

Rohith K N
Rohith K N

Reputation: 871

I think your IDE have find and replace option.

Add /* at starting and */ at ending

Within the code block

Replace */ with *//*

then to if you want to remove the comments you made :

Remove /* at starting, Remove */ at ending

Within the code block

Replace *//* with */

Upvotes: 6

Related Questions