Learn JavaScript
Advanced JavaScript


We can also use const to create a variable and store a value in it.

In the example given below, the variable fruit stores the value Apple.

There are two things that we must keep in mind when we use const:

  • We can’t change the value of a const.

  • We must give a value to it as soon as we create it.

In the example given below, when we try to change the value of the variable fruit, it throws an error.

If we create a variable using const and do not provide it a value instantly, it throws an error.