How to use 'const' keyword in JavaScript?

JavascriptWeb DevelopmentFront End Technology

The value of const remains the same, you can’t change and declare it again. Create a read-only reference with the “const” declaration. 

With const, you can declare local variables with block scope rather than function scope. Let’ say we have a constant variable a. After declaring a value like a constant variable, you can’t assign a new value to it.

// declared ‘a’ as a constant variable.
const a = 150;
// Assigning a new value to `a` will fail since ‘a’ is a constant variable
a= 0;
a++;
// The below declarations won’t work
var a = 0;
raja
Ali
Published on 17-Jan-2018 16:26:02
Advertisements