{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":627,"path":"api-reference/scripts/considerations-switching-javascript-mode.md","title":"Considerations for switching JavaScript modes","bundle":null,"doc_type":null,"release":"australia","body":"\n# Considerations for switching JavaScript modes\n\nSwitching 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.\n\nFor more information about each JavaScript mode, see [JavaScript modes](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_JS_modes.md) and [JavaScript engine feature support](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/javascript-engine-feature-support.md).\n\nThis 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\\).\n\n<table id=\"table_r4b_j4r_fcc\"><thead><tr><th>\n\nFeature\n\n</th><th>\n\nCompatibility Mode\n\n</th><th>\n\nES5 Standards Mode\n\n</th><th>\n\nECMAScript 2021 \\(ES12\\)\n\n</th></tr></thead><tbody><tr><td>\n\nArguments object\n\n</td><td>\n\nThe `arguments` object exists, but there's no `strict mode`, so modifications reflect on `arguments`. Prints: ```javascript\n*** Script: [object Arguments]\n*** Script: [object Arguments]\n*** Script: [object Arguments]\n*** Script: 123\n```\n\n</td><td>\n\nIn strict mode, the arguments object doesn’t reflect parameter modifications and throws an error. Prints: ```javascript\nsn_es5: 123\nsn_es5: undefined\nsn_es5: [object Arguments]\nsn_es5: 123\n```\n\n</td><td>\n\nThe same as ES5.\n\n</td></tr><tr><td>\n\nBoolean overrides\n\n</td><td>\n\nPrimitive Booleans \\(`true`, `false`\\) can be overridden, causing unexpected behavior.\n\n</td><td>\n\nPrimitive Booleans are more protected, though still can be overridden when assigned to variables.\n\n</td><td>\n\nThe same as ES5, but strict mode helps prevent some assignments. The conditional expression should be written in this form: ```javascript\n(cond_expr instanceof Boolean ? cond_expr.valueOf() : cond_expr).\n```\n\n</td></tr><tr><td>\n\nException for syntax errors\n\n</td><td>\n\nSyntax errors throw exceptions at runtime. Error handling is inconsistent. Example: ```javascript\nJavascript compiler exception: unterminated string literal (null.null.script; line 1) in:\nvar b = '\n```\n\n</td><td>\n\nMore consistent syntax error handling, especially in strict mode. Example: ```javascript\nEvaluator: com.glide.script.RhinoEcmaError: unterminated string literal\n   script : Line(1) column(9)\n==>   1: var b = '\n```\n\n</td><td>\n\nThe same as ES5, but with more robust handling and clearer error messages in updated engines. Example: ```javascript\nSyntaxError: Unterminated string constant at line 1\n\n==>   1: var b = '\n```\n\n</td></tr><tr><td>\n\nIncrement and decrement\n\n</td><td>\n\nAllowed on variables but could behave unexpectedly with complex expressions. Prints: ```javascript\n*** Script: c: 1\n*** Script: gr.related_incidents: 1\n*** Script: 2\n*** Script: 3\n```\n\n</td><td>\n\nImproved clarity, but still allowed on variables \\(`var`, `let`, `const`\\). Prints: ```javascript\nsn_es5: c: 0\nsn_es5: gr.related_incidents: 1\nsn_es5: 1\nsn_es5: 2\n```\n\n</td><td>\n\nThe same as ES5, with stricter rules in some contexts \\(for example, `const`\\).\n\n</td></tr><tr><td>\n\nLine continuations\n\n</td><td>\n\nAllowed with a backslash \\(`\\`\\) but discouraged due to readability issues. In this example, all three functions are called. ```javascript\nvar expr = doFoo();  // do foo\n           doBar();  // do bar \n           finish();   // all done\n eval(expr);\n\n```\n\n</td><td>\n\nSame 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.\n\n</td><td>\n\nThe same as ES5, but template literals provide a more readable alternative.\n\n</td></tr><tr><td>\n\nMissing semicolons\n\n</td><td>\n\nAutomatic semicolon insertion \\(ASI\\) often led to unexpected behavior.\n\n</td><td>\n\nThrows a syntax error when a semicolon is missing.\n\n</td><td>\n\nThe same as ES5. Updated practices encourage explicit semicolons.\n\n</td></tr><tr><td>\n\nNon-existent functions\n\n</td><td>\n\nCalling a non-existent function throws a `ReferenceError`.\n\n</td><td>\n\nThrows a `TypeError` if a non-function is called.\n\n</td><td>\n\nThrows an EcmaError when a non-existent function is called or a property is referenced.\n\n</td></tr><tr><td>\n\nNon-existent properties\n\n</td><td>\n\nAccessing a non-existent property returns `undefined`; no error thrown.\n\n</td><td>\n\nSame as pre-ES5.\n\n</td><td>\n\nThe same as Compatibility mode and ES5 Standards mode.\n\n</td></tr><tr><td>\n\nNumeric literals\n\n</td><td>\n\nBasic decimal and hexadecimal literals.\n\n</td><td>\n\nIntroduced stricter parsing rules and better handling of numeric literals.\n\n</td><td>\n\nAdded binary \\(`0b`\\), octal \\(`0o`\\), and BigInt literals \\(`123n`\\).\n\n</td></tr><tr><td>\n\nReserved keyword as property\n\n</td><td>\n\nUsing reserved keywords isn't possible.\n\n</td><td>\n\nReserved keywords can be used as property names without error, for example, `obj.for`. Prints the object when returned.\n\n</td><td>\n\nThe same as ES5.\n\n</td></tr><tr><td>\n\nTreat let and yield as keywords\n\n</td><td>\n\n`let` and `yield` aren’t keywords and can be used as identifiers only.\n\n</td><td>\n\n`let` is introduced as a keyword. `yield` is reserved in strict mode.\n\n</td><td>\n\nBoth are keywords. Using them as identifiers throws syntax errors.\n\n</td></tr></tbody>\n</table>**Parent Topic:**[JavaScript modes](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_JS_modes.md)\n\n"}}