/
How const can be helpful in modern Javascript

How const can be helpful in modern Javascript

const is useful because it binds the variable to a name and means you cannot re-assign it. So you can do this:

const DAYS_WEEKEND = ["Saturday", "Sunday"]; DAYS_WEEKEND = [1,2,3]; // One cannot re-assign a const variable.

This code is following a popular convention of putting constants in capitals - as often used in C.

 

Related content

Why let is better than var
Why let is better than var
More like this
Javascript Object
Javascript Object
More like this
The equality operator in Javascript == does implicit type conversions
The equality operator in Javascript == does implicit type conversions
Read with this
Javascript strings are immutable
Javascript strings are immutable
More like this
Dealing with loops with create Closures
Dealing with loops with create Closures
Read with this
Javascript is a dynamic language
Javascript is a dynamic language
More like this