JavaScript modes

  • Release version: Washingtondc
  • Updated February 1, 2024
  • 2 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 JavaScript modes

    JavaScript modes are design and runtime settings for custom applications in ServiceNow. They support existing server-side scripts and new scripts developed according to the ECMAScript 2021 standard. The available modes are ECMAScript 2021 (ES12), ES5 Standards, and Compatibility. The default mode for new scoped applications is ECMAScript 2021 (ES12), while ES5 Standards is the default for global applications.

    Show full answer Show less

    Key Features

    • ECMAScript 2021 (ES12) Mode: Supports modern JavaScript features such as default function parameters, rest parameters, arrow functions, and optional chaining. It does not maintain legacy behaviors from pre-Tokyo JavaScript engine.
    • ES5 Standards Mode: Available for global and scoped applications, this mode supports ES5 syntax and features like "use strict" declaration, new Array and Date methods, and compatibility with modern libraries.
    • Compatibility Mode: Designed for scripts created before ES5 Standards mode. It utilizes ES5 Native JSON methods but does not support third-party libraries.

    Key Outcomes

    By configuring the appropriate JavaScript mode for your application, you can leverage modern JavaScript features or maintain compatibility with older scripts. This flexibility allows developers to optimize application performance and ensure smoother transitions when upgrading or modifying applications.

    JavaScript mode is a design and runtime setting for custom applications. To support existing server-side scripts and new scripts developed to the ECMAScript 2021 standard, the JavaScript engine has three modes: ECMAScript 2021 (ES12), ES5 Standards, and Compatibility.

    You configure an application to use one of three JavaScript modes. The default mode for new scoped applications is ECMAScript 2021 (ES12) and for new global applications, it is ES5 Standards.

    To modify a JavaScript mode

    To modify the JavaScript mode in a custom application, you need admin or a delegated developer role granting full access.

    1. Find and select your custom application listed in the Custom Application [sys_app] table.
    2. Under Design and Runtime, select an available option from the JavaScript Mode menu.

    See also Update a custom application record.

    ECMAScript 2021 (ES12) mode

    ECMAScript 2021 (ES12) mode is the default mode when you create new scoped applications. This mode doesn’t preserve the legacy behaviors in the pre-Tokyo JavaScript engine or work with global scripts.

    ECMAScript 2021 (ES12) mode supports a subset of ECMAScript 2021 (ES12) and ECMAScript 2022 (ES13) syntax and features, including the following features:
    • Default function parameters
    • Rest parameters
    • For-of loops
    • Template literals
    • Destructuring
      • Declarations
      • Assignment
      • Parameters
    • Const declaration
    • Let declaration
    • Arrow functions
    • Class declarations
    • Map set
    • Optional chaining operator (?.)

    To learn about specific ECMAScript 2021 (ES12) features, see the Let's Learn ECMAScript 2021 videos on the ServiceNow Dev Program YouTube channel.

    ES5 Standards mode

    ES5 Standards mode is the default mode for global applications and is an option for scoped applications. This mode doesn’t preserve the legacy behaviors in the pre-Helsinki JavaScript engine.

    ES5 standards mode supports ECMAScript5 syntax and features, including the following features:
    • The "use strict" declaration
    • Control over extensibility of objects
    • Get and set properties on objects (accessors)
    • Control over writability, configurability, and enumerability of object properties
    • New Array and Date methods
    • Native JSON support
    • Support for modern third-party libraries such as lodash.js and moment.js

    For more information about features supported by the ECMAScript 2021 (ES12) and ES5 Standards modes, see JavaScript engine feature support.

    Compatibility mode

    Compatibility mode is used for all scripts developed prior to the addition of ES5 Standards mode. Compatibility mode has some differences from the previous JavaScript engine.

    JSON support changes:
    • JSON.stringify() and JSON.parse() are implemented using the ES5 Native JSON object.
    • The new JSON().encode() and new JSON().decode() are still supported, but should only be used when the legacy behavior is required.

    The use of third-party JavaScript libraries isn’t supported in Compatibility mode.