Posted on Arjun

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.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun

I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.


DMCA.com Protection Status