Javascript is a very controversial programming language, you either love it or you hate it. Many love it, many hate it. Be that as it may, Javascript remains the engine of the web. It adds dynamism to the web in the way CSS styles the web. In Javascript, we need to hold values and other things which is why you need variables, variables are containers that can help you do these things. Variables are meant to do different things in different scopes (like location or block of code) and contexts.
In Javascript we have three types of variables;
Var
Const
Let
The variable type “Var” is used to refer to values that are used everywhere but can be given different values depending on where it is used. Eg. The word “tea”, depending on where you are, can mean a beverage that is prepared from extracts or derived from plants like Jasmine or Camomile. It can also mean a chocolate drink in Nigeria (something others refer to as cocoa). As a convention, we avoid using this type of variable in Javascript as it can become difficult to keep track of its values in a huge project because it can be mistakenly assigned a new value than the original value.
The variable type “Const” is used to refer to constants, they can only be defined once, you can’t change your mind and give it a new meaning. It’s useful in declaring fixed values that you will be using throughout a project eg. Averagely, the speed of light is constant regardless of where you go.
The variable type “Let” is used to define things that you want to have a particular meaning in a place and another meaning in another place or context. Examples are slangs or nicknames eg. Weed. Depending on where you are and what context it’s being mentioned, Weed, Trees, and Marijuana can mean the same thing. This helps in assigning values within a small block of code and using that same variable name to refer to other things in other blocks of code.