Considerations for switching JavaScript modes

  • Release version: Australia
  • Updated March 12, 2026
  • 3 minutes to read
  • Summarize
    Summarized using AI
    This content was generated using new OpenAI-powered functionality. Results are provided on an as is basis and are not guaranteed to be accurate or complete.

    Summary of Considerations for Switching JavaScript Modes

    Switching JavaScript modes in applications or scripts can significantly alter the behavior of existing scripts. It is crucial to understand these changes to avoid issues. This guide provides insights into the differences between Compatibility Mode, ES5 Standards Mode, and ECMAScript 2021 (ES12).

    Show full answer Show less

    Key Features

    • Arguments Object: In strict mode, modifications to the arguments object throw errors.
    • Boolean Overrides: ES5 allows primitive Booleans to be overridden, whereas strict mode adds some protection against unexpected behavior.
    • Exception Handling: ES5 has inconsistent error handling; ES5 Standards Mode and ES12 improve this with clearer messages.
    • Increment and Decrement: Allowed with variables but ES12 enforces stricter rules especially for constants.
    • Line Continuations: While allowed in all modes, ES12 promotes template literals for better readability.
    • Missing Semicolons: ES5 allows automatic semicolon insertion, which can lead to errors; ES12 encourages explicit semicolons.
    • Non-existent Functions and Properties: Different modes handle errors when calling non-existent functions or accessing properties, with ES12 providing stricter error messages.
    • Numeric Literals: ES12 introduces new literal formats, improving parsing and handling.
    • Reserved Keywords: Using reserved keywords as property names is restricted in strict modes, with ES12 treating keywords like 'let' and 'yield' as non-identifiers.

    Key Outcomes

    By understanding these behavioral changes, ServiceNow customers can effectively manage their JavaScript applications, ensuring compatibility, improving error handling, and leveraging new features in the latest ECMAScript versions. This knowledge will help in troubleshooting issues that may arise post-switching and enhance the overall reliability of scripts in their applications.

    Switching the JavaScript mode for an application or script might change the behavior of existing scripts. Review some examples of behavior changes before switching JavaScript modes or to troubleshoot any issues that you experience after switching.

    For more information about each JavaScript mode, see JavaScript modes and JavaScript engine feature support.

    This table highlights how JavaScript behavior has evolved from the lenient and error-prone pre-ES5 environment, to the stricter and more predictable ES5, and lastly the more feature-rich environment of ES12 (ECMAScript 2021).

    Table 1. Behavioral differences in JavaScript modes
    Feature Compatibility Mode ES5 Standards Mode ECMAScript 2021 (ES12)
    Arguments object The arguments object exists, but there's no strict mode, so modifications reflect on arguments. Prints:
    *** Script: [object Arguments]
    *** Script: [object Arguments]
    *** Script: [object Arguments]
    *** Script: 123
    In strict mode, the arguments object doesn’t reflect parameter modifications and throws an error. Prints:
    sn_es5: 123
    sn_es5: undefined
    sn_es5: [object Arguments]
    sn_es5: 123
    The same as ES5.
    Boolean overrides Primitive Booleans (true, false) can be overridden, causing unexpected behavior. Primitive Booleans are more protected, though still can be overridden when assigned to variables. The same as ES5, but strict mode helps prevent some assignments. The conditional expression should be written in this form:
    (cond_expr instanceof Boolean ? cond_expr.valueOf() : cond_expr).
    Exception for syntax errors Syntax errors throw exceptions at runtime. Error handling is inconsistent. Example:
    Javascript compiler exception: unterminated string literal (null.null.script; line 1) in:
    var b = '
    More consistent syntax error handling, especially in strict mode. Example:
    Evaluator: com.glide.script.RhinoEcmaError: unterminated string literal
       script : Line(1) column(9)
    ==>   1: var b = '
    The same as ES5, but with more robust handling and clearer error messages in updated engines. Example:
    SyntaxError: Unterminated string constant at line 1
    
    ==>   1: var b = '
    Increment and decrement Allowed on variables but could behave unexpectedly with complex expressions. Prints:
    *** Script: c: 1
    *** Script: gr.related_incidents: 1
    *** Script: 2
    *** Script: 3
    Improved clarity, but still allowed on variables (var, let, const). Prints:
    sn_es5: c: 0
    sn_es5: gr.related_incidents: 1
    sn_es5: 1
    sn_es5: 2
    The same as ES5, with stricter rules in some contexts (for example, const).
    Line continuations Allowed with a backslash (\) but discouraged due to readability issues. In this example, all three functions are called.
    var expr = doFoo();  // do foo
               doBar();  // do bar 
               finish();   // all done
     eval(expr);
    
    Same as Compatibility mode; no change in handling line continuations. In the previous example, ES5 only calls the first function and treats everything after the first comment including the newline as comment until the expression end. The same as ES5, but template literals provide a more readable alternative.
    Missing semicolons Automatic semicolon insertion (ASI) often led to unexpected behavior. Throws a syntax error when a semicolon is missing. The same as ES5. Updated practices encourage explicit semicolons.
    Non-existent functions Calling a non-existent function throws a ReferenceError. Throws a TypeError if a non-function is called. Throws an EcmaError when a non-existent function is called or a property is referenced.
    Non-existent properties Accessing a non-existent property returns undefined; no error thrown. Same as pre-ES5. The same as Compatibility mode and ES5 Standards mode.
    Numeric literals Basic decimal and hexadecimal literals. Introduced stricter parsing rules and better handling of numeric literals. Added binary (0b), octal (0o), and BigInt literals (123n).
    Reserved keyword as property Using reserved keywords isn't possible. Reserved keywords can be used as property names without error, for example, obj.for. Prints the object when returned. The same as ES5.
    Treat let and yield as keywords let and yield aren’t keywords and can be used as identifiers only. let is introduced as a keyword. yield is reserved in strict mode. Both are keywords. Using them as identifiers throws syntax errors.