June 2016
Intermediate to advanced
910 pages
18h 59m
English
The ES6 const keyword is used to declare the read-only variables, that is, the variables whose value cannot be reassigned. Before ES6, the programmers usually used to prefix the variables that were supposed to be constant. For example, take a look at the following code:
var const_pi = 3.141; var r = 2; console.log(const_pi * r * r); //Output "12.564"
The value of pi should always remain constant. Here, although we have prefixed it, there is still a chance that we might accidentally change its value somewhere in the program, as they're no native protection to the value of pi. Prefixing is just not enough to keep the track of the constant variables.
Therefore, the const keyword was introduced to provide a native protection to the ...
Read now
Unlock full access