Utilizor
Contact Us

JS Const

The const keyword was introduced in ES6 (2015). Variables defined with const cannot be Redeclared or Reassigned.

The const Keyword in JavaScript

Variables declared with const are block-scoped, similar to let.

However, their value cannot be changed through reassignment, and they cannot be redeclared. This makes them ideal for values that you know won't change, like mathematical constants or configuration settings.

Note: For objects and arrays declared with const, the contents of the object/array can still be changed, but the variable cannot be reassigned to a new object/array.

Example

const PI = 3.14159;
// PI = 3.14; // This would cause a TypeError