Loading lesson path
Concept visual
Start at both ends
ES6 (2015)
A variable defined with the const keyword cannot be reassigned:
const PI = 3.141592653589793;
PI = 3.14; // This will give an error
PI = PI + 10; // This will also give an errorMust be Assigned const variables must be assigned a value when they are declared:
Correct const PI = 3.14159265359;
Incorrect const PI;
PI = 3.14159265359;Always declare a variable with const when you know that the value should not be changed.The keyword const is a little misleading.It does not define a constant value. It defines a constant reference to a value. Because of this you can NOT:
You can change the elements of a constant array:
// You can create a constant array:
const cars = ["Saab", "Volvo", "BMW"];// You can change an element:
cars[0] = "Toyota";// You can add an element:
cars.push("Audi");But you can NOT reassign the array: