CodeQL documentation

Conditional comments

ID: js/conditional-comment
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
Tags:
   - quality
   - reliability
   - correctness
   - portability
   - language-features
   - external/cwe/cwe-758
Query suites:
   - javascript-security-and-quality.qls

Click to see the query in the CodeQL repository

Conditional comments are only supported in Internet Explorer and should be avoided for portability.

Recommendation

Use feature detection (as offered by major frameworks such as jQuery) instead.

Example

The following code snippet uses conditional comments to detect whether it is running on Internet Explorer 9 or newer. A better alternative would be to directly check for the desired features using, for instance, jQuery’s $.support object.

/*@cc_on
  @if (@_jscript_version >= 6)
    console.log("You're running a new version of IE.");
  @else
    console.log("You're running an old version of IE.");
  @end
  @*/

Note that conditional comments are no longer supported in Internet Explorer 11 Standards mode.

References

  • © GitHub, Inc.
  • Terms
  • Privacy
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy