What are variables?

What are variables?

Have you ever attempted to drink water without any container? Just using your hands to scoop the water. You will find that it’s not the most pleasant way to drink water. In computer programming languages eg. Javascript, we as programmers need to hold things, store things and use things. The best way to engage in these activities is with a container.

Variables are containers that you can use to hold things. Every variable has a name and that name is used to identify the value that the variable is holding for us. Think of it like our names as humans. When we call that name we’re not calling just any human being, we’re using it to refer to a particular human being with that name. In a way, the human being is the name and the name is the human being. The name is nothing without the human being and it’s harder to identify the human being without the name.

In Javascript we have three types of variables; Var, Const, and 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 “gas”, depending on where you are can mean a state of matter or gas (stored in cylinders and used as a source of fuel) or gasoline (a liquid fuel used to power vehicles and other machines). 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. Pi is 3.14159265359. 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. 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.