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.

Scenario

SuiteScript 2.0 Behavior

SuiteScript 2.1 Behavior

Set a value for a const variable and then try to assign it a new value:

                    const recordId = 1;
recordId = 2;
log.debug("recordId", recordId); 

                  

The script executes successfully, however the value of recordId is not changed by the recordId = 2; line. The log statement will write: recordId 1.

Script execution stops at the recordId = 2; line, and the following error is generated:

TypeError: Assignment to constant variable

Related Topics

General Notices