SuiteScript 2.1 uses a different runtime engine than SuiteScript 2.0, also supports ECMAScript language features that are not supported in SuiteScript 2.0. This causes some capabilities in SuiteScript 2.0 scripts to function differently when the script is executed using SuiteScript 2.1.
The following sections describe important differences between SuiteScript 2.0 and SuiteScript 2.1:
Reserved Words as Identifiers
In the ECMAScript specification, reserved words are identifiers that have special meaning. For example, the var reserved word indicates a variable declaration. You cannot use reserved words as variable names, labels, or function names in JavaScript/ECMAScript. Because SuiteScript 2.1 supports a later edition of the ECMAScript specification (ECMAScript 2019) than SuiteScript 2.0 (ECMAScript 5.1), the list of reserved words is different. SuiteScript 2.1 is stricter about not including reserved words in scripts.
Invalid JSON Parsing
SuiteScript can parse JSON strings that you use in your scripts. When invalid JSON is encountered, a syntax error is generated. The type and format of the generated error message is different in SuiteScript 2.1 than in SuiteScript 2.0. Also, including trailing commas in JSON strings is accepted in SuiteScript 2.0 but generates an error in SuiteScript 2.1.
Strict Mode
ECMAScript 5 introduced strict mode. If a SuiteScript 2.0 script assigns a value to a variable without first declaring the variable using the var or const keyword, the script continues executing and no error is thrown. If a SuiteScript 2.1 script assigns a value to a variable without using the var , let, or const keyword, an error is thrown.
Reassignment of const Variables
JavaScript const variables create a read-only reference to a value. When a const variable is assigned a value, the variable identifier cannot be used again (reassigned). In SuiteScript 2.0, no error is thrown when you reassign a const variable. In SuiteScript 2.1, a TypeError is thrown.
Behaviour of for…each…in Statement
The for…each…in statement was deprecated as part of ECMA-357 (4x) specifications and should no longer be used. In SuiteScript2.0, the for…each…in statement is accepted. In SuiteScript 2.1, a SyntaxError is thrown if you try to use the for…each…in statement in your script.
Formats for Converting Dates to Local Date Strings
JavaScript supports several date formats and ways to create a date. After you create a date, you can convert it to a local date string. In SuiteScript 2.0, the default format for the converted date string is the long format. In SuiteScript 2.1, the default format for the converted date string is the short format.
Conditional Catch Blocks
In JavaScript, a try-catch statement can include an optional if statement within the catch block, however it is not ECMAScript specification compliant. In SuiteScript 2.0, a script that includes a conditional catch statement executes without error. In SuiteScript 2.1, a SyntaxError is thrown for any script that includes a conditional catch statement.
The toSource Method
In JavaScript, the toSource method is used to return a string representing the source code of the object. However, this feature is obsolete and should not be used. In SuiteScript 2.0, a script that includes the toSource method for an object executes without error. In SuiteScript 2.1, an error is thrown for any script that includes the toSource method for an object.
Set Decimal Number with Trailing Zeros
When you set a decimal number value in JavaScript, behavior depends on the format of the numerical value. In SuiteScript 2.0, if there are trailing zeros in a decimal value you set, the value is set as a double precision floating point number (double). In SuiteScript 2.1, if there are trailing zeros in a decimal value you set, the value is set as an integer value. Note that in both SuiteScript 2.0 and SuiteScript 2.1, a value is always set as a double value if there are no trailing zeros in the decimal value you specify.
String Differences for RESTlet Post Method
In SuiteScript 2.0, a JSON.stringify() call is added internally to whatever is passed in the post() method of a RESTlet. This affects the value passed. In SuiteScript 2.1, a JSON.stringify() call is not added to the post() method for a RESTlet.
ParseInt Difference
The parseInt function operates differently in SuiteScript 2.1 than it did in SuiteScript 2.0, for certain calls to parseInt.
Error Object Properties
SuiteScript supports the Error object, which is provided by ECMAScript, to represent errors that can occur in scripts. You can call JSON.stringify(obj) on an Error object to obtain a string representation of the error. If you pass an argument to the constructor when you create the Error object, the string representation in SuiteScript 2.0 includes this argument as the value of the message property. The string representation in SuiteScript 2.1 does not include the message property.
This difference is because of how JSON.stringify(obj) handles enumerable and non-enumerable properties. In SuiteScript 2.0, the output of JSON.stringify(obj) includes the content of both enumerable and non-enumerable properties. In SuiteScript 2.1, the output of JSON.stringify(obj) includes only the content of enumerable properties and does not include the content of non-enumerable properties, as per the ECMAScript specification.
When you pass an argument to the Error object constructor, a non-enumerable message property is defined. If you change the value of this property after the Error object is created, the property remains non-enumerable. So, when an Error object is created in this way, the message property is not included in the JSON.stringify(obj) output in SuiteScript 2.1 scripts.
By contrast, when you do not pass an argument to the Error object constructor, the message property is not defined. If you try to set the value of this property after the Error object is created, a new message property is defined. Properties that are defined in this way are always enumerable. So, when an Error object is created in this way, the message property is included in the JSON.stringify(obj) output in SuiteScript 2.1 scripts.