const myConstant = 0;
const myConstant = 0; myConstant = 1; // This will generate an error
A constant is created using the
const keyword. A value is assigned to the constant using the equals sign.
You can use constants to hold many different types of values: strings, numbers, booleans, arrays, objects, etc.
const name = 'John Smith';
If a constant name is composed of multiple words, then the first word is written in lowercase letters while the first letter of each subsequent word is capitalized, like this:
const myFirstName = 'John';
Try the following statements in the console:
const myConstant = 10 myConstant = 11
The second line will generate an error since you can’t change the value of a constant.