Const - Prevent Variable Reassignment
In JavaScript, const
is a keyword that is used to declare a variable with a value that cannot be reassigned. This means that once you assign a value to a const
variable, you cannot change that value later in your code.
For example, if you declare a variable like this:
Loading Code . . .
You cannot do this later in your code:
Loading Code . . .
This will result in an error.
However, you can still access the value of the const variable using its name, just like any other variable. So you can still do this:
Loading Code . . .
In the code below we have a variable myNumber
that is being changed by a random number.
Prevent the variable from changing by changing its declaration with const
.
Loading...
Loading...