ES-6 introduced the support for immutable variables or constant variables. Constant variables are not a new concept in programming and have been in existence in most of the programming languages of today.
If while programming you come across a scenario where you don’t want somebody to change value of a variable then it makes sense to declare the variable as constant. You must understand that you cannot reassign a constant variable to a new value but in case of objects you can still be able to modify the property of objects.
Some rules accompanying a constant variable:
a.) Must be declared using const keyword
b.) Must be initialized at time of declaration
c.) Cannot change value of const once assigned
Let’s try to understand with examples
Constant variable also has blocked scope just like let keyword explained in previous articles.
this is a test
SCRIPT5009: ‘somedata’ is undefined