Constants are block-scoped variables/arrays/objects which cannot be reassigned or redeclared in the same scope (Scope is defined by the nearest curly braces). Const declaration creates a read-only reference to a value but it is not immutable.

Syntax - const nameN = valueN;

Variable scope

Constant scope can be global/local depending on the block in which it is declared. However, you cannot access constant as window object property.


constPI = 3.14;

console.log(window.PI) //output: undefined


Slow performance if code executes in temporal dead zone (i.e. accessing block scoped variable before definition is evaluated. Block scoped variables are not hoisted therefore accessing it before definition evaluation results in ReferenceError.)

#constants #es6 #es6 concepts

ES6 Concepts - Part One
1.40 GEEK