JavaScript tutorial:
Conditional compilation

 

Conditional compilation allows the use of new JavaScript language features without sacrificing compatibility with browsers that don't support the features.

Example

Conditional compilation is activated by using the @cc_on statement, or using an @if or @set statement outside of a comment. Some typical uses for conditional compilation are using new features in JavaScript, embedding debugging support into a script, and tracing code execution.

It is strongly recommended that conditional compilation code be placed in comments

/*@cc_on @*/
/*@if (@_jscript_version == 4)
alert("JavaScript version 4");
@else @*/
alert("You need a more recent script engine.");
/*@end @*/

To run the code above, paste it into JavaScript Editor, and click the Execute buttons

This example uses special comment delimiters that are only used if conditional compilation is activated by the @cc_on statement. Scripting engines that do not understand conditional compilation only see the message informing of the need for a new scripting engine.

See Also: Conditional Compilation Variables, @cc_on Statement, @if Statement, @set Statement