Error guides

Fix "TypeError: Assignment to constant variable." on V8

TypeError: Assignment to constant variable.

Why it happens

In Rhino, const was a Mozilla extension: assigning a new value was silently ignored — no error, the old value stayed. V8 follows the standard and throws.

const TAX_RATE = 0.07;
TAX_RATE = 0.08;     // Rhino: ignored, still 0.07. V8: TypeError

Common sources: for (const i = 0; i < n; i++), config constants overwritten in a setup function, counters declared const.

The fix

Decide what the code meant:

let taxRate = 0.07;
if (region === 'CA') taxRate = 0.0825;

for (let i = 0; i < rows.length; i++) { … }

Gotcha

Switching to let/var changes behaviour compared to Rhino: the new value now sticks. That's usually the intended behaviour, but check it.

How V8Shift handles it

Each const that is reassigned anywhere later in the file is rewritten to var and marked V8Shift: review so you can confirm the intent.

Have a whole project to migrate? Paste your .gs or upload a zip for a free V8 compatibility report — every occurrence of this pattern with file and line, plus an auto-rewritten project.
Related errors