1

I did a google search for the answer but I've probably overlooked something obvious... I wish to comment out a block of code that has the potential to have nested comments, where they can terminate the parent comment early. In c I've seen it done like follows:

#if 0
    /* Code */
#endif

but js doesn't seem to have standard preprocessor. Is there a way?

4 Answers 4

4

I'd just do something like:

if ( ! "DEBUG" ) {

  ...

}
Sign up to request clarification or add additional context in comments.

Comments

2

Seems that I can comment out any block by doing:

1|| /* code block */

It even works before statements because js seems to treat them as expressions as well, for instance

1|| if(1) /* code */

will 'comment out' that if block.

Comments

1

javascript don't provide preprocessor but you can use use third-party library

http://code.google.com/p/jsmake-preprocessor/

ex)

/*@ifdef DEBUG_MODE */

console.log("development server is in debug mode!");

/*@end */

1 Comment

So no standard way of commenting out code blocks? Oh well. I think I'll just work around the limitation rather than extend the code. It's not like I need a preprocessor for anything else.
0

Javascript multiline comments, also known as block comments, start with a forward slash followed by an asterisk (/*) and end with an asterisk followed by a forward slash (*/). They do not require a comment delimiter character on every line and may contain newlines

source

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.