const has been updated to be ES6 compatible

Published: | Categories: JavaScript

Description

The support for const statement has been updated to comply with the ECMAScript 6 spec. First, it is now block-scoped like the let statement, so { const a = 1 }; a; will throw a ReferenceError instead of just returning 1. Second, it will require an initializer, so const a; now throws a SyntaxError. Third, it cannot be redeclared anymore, so const a = 1; a = 2; also throws a SyntaxError.

References