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.

Updated on: 2020-01-13T10:18:44+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements