Skip to content

JavaScript const keyword

In my previous post I wrote about let keyword, in this post I would like to write about another new ECMAScript 6 keyword, const.

There is no much difference between const and let, both works similar way , both are having same level of scope.
Which means constants which are declared with const keyword are block scoped local variables which means they are limited in scope to the block, statement, or expression on which it is used.

We can not re-assign a value to constant, and you can not re-declare a constant . For example, if we have const a = 1, and then later down in the same code block, if we try to reassign const a = 2 or a = 2, JavaScript engine will throw an exception.

Using const and let, you get the same type of scoping, and just slightly different behavior with respect to reassigning/redefining values.

A constant cannot share its name with a function or a variable in the same scope.

0 0 votes
Article Rating
Notify of

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments