DEV Community


Posted on

Day 83 : #100DaysofCode - Reviewing variables of JS

Today I began reviewing the basics of Javascript and completed some lessons from my bootcamp. I am reviewing variables and scopes.

For variables, I found the following quote from my bootcamp valuable:

Use var... never.

Use let... when you know the value of a variable will change. For example, a counter variable that starts at 0 and is subsequently incremented to 1, 2, 3, and so on. In the lessons on looping and iteration in JavaScript, let will have its moment in the spotlight.

Use const... for every other variable.
Best practice is to always declare variables with const and then, if you later realize that the value has to change over the course of your program, circle back to change it to let.

The var keyword allows us to overwrite variable declarations without an error. Unlike, const or let where a variable with the same name can only be declared once.

The var keyword is declared globally, or locally if declared inside a function. Unlike the let keyword, which inside a block, statement, or expression, its scope is limited to that block, statement, or expression.

I found other blogs on var, const, and let that may be helpful:

FreeCodeCamp Article

Look what I did! It is small but it is just the beginning

As always, thanks for reading!


Song of the day: Throwback

Top comments (0)