← Back to release summary

Let all early errors be SyntaxErrors

Category
JavaScript
Type
New or changed feature
Status
In development (Chrome In development)
Intent stage
Evaluate readiness to ship

WPT details:

Summary

Replace all early ReferenceErrors with early SyntaxErrors.

Motivation

The spec has been inconsistent with respect to the "early ReferenceError" notion: only update/assignment expressions (e.g. `0++`, `0 = 0`) throw early ReferenceErrors, while other invalid assignments like `[0] = []` and `for (0 of []) {}` throw early SyntaxErrors. Furthermore, this becomes an observable concern with eval. If eval throws a ReferenceError, the user has had no way to know whether the code was actually executed or simply parsed (short of matching on error message strings).

Standards & signals

Ecosystem

Explainers: https://github.com/tc39/ecma262/pull/1527

View on chromestatus.com