JavaScript Variables
In JavaScript, we use variables to store and track information. 

Variables are one of the most important concepts in programming. A variable is a way of storing and keeping track of information in a program so that it can be later used and manipulated.

For example, the code console.log() we just talked about is accepting variables inside the parentheses.

Create and Change Variables

A variable is like a box that you labeled with a unique name. By assigning a variable, you put something inside the box. You can also reassign it, which means you empty the box and put something new in the box. Even though the contents of the box changes, it's still always the same box with the unique label you gave it.

Declare a variable

To use a variable, we need to declare a variable first. This is the step of labelling your box.
Use the var, const, or let keyword followed by the variable name to declare a variable. 
*These 3 keywords are different when it comes to reassigning variables. 

var studentName;
const pi;
let message;
Don’t forget to put a semicolon at the end of each JavaScript statement.

Name a variable

There are a few rules you'll need to follow when creating a variable:
  • JavaScript has some reserved keywords that you can't use for a variable name. Using them can cause a syntax error.
  • Names can't start with a number.
  • Names can only contain letters, numbers, and the $ and _ characters.
  • When you want to create a variable name with multiple words, there’s a convention to use camel case, which is to capitalize every word after the first word. 
  • For example: currentStudentName

Read more: variable naming rules

Assign a variable

Once you’ve declared a variable, you can assign a value to it. 
You’ll use an equal sign to assign the value to it. 
The equal sign here doesn’t mean “equal to”. It’s an assignment operator

These following lines means to put whatever is on the right side of the equal mark into the box labelled with the name on the left side.
studentName = "Mengyi";
pi = 3.14;
message = "hello";

Most of the time, we declare and assign the value of a variable in a single statement.
var studentName = "Mengyi";
const pi = 3.14;
let message = "hello";

Use a variable

Once you’ve declared and assigned a variable, you can access and use its assigned value whenever you need it in the code after
let message = "hello";
console.log(message);
When using the variable, you just need to write the variable's name, without quotes or any other punctuation.