Computer >> Computer tutorials >  >> Programming >> Javascript

How to define integer constants in JavaScript?


ECMAScript allows usage of const to define constants in JavaScript. To define integer constants in JavaScript, use the const,

const MY_VAL = 5;
// This will throw an error
MY_VAL = 10;

As shown above, MY_VAL is a constant and value 5 is assigned. On assigning, another value to a constant variable shows an error.

Using const will not allow you to reassign any value to MY_VAL again. If you will assign a new value to a constant, then it would lead to an error.