A variable is a container that stores a value or values. You can use variables to store data, like text strings, numbers, or arrays.
Checkout this video:
A variable name must start with a letter (a-z), an underscore (_), or a dollar sign ($).
After the first character, a variable name can contain any combination of letters (a-z), underscores (_), and dollar signs ($).
A variable name cannot contain any spaces.
A variable name cannot be a reserved word. (For example, you cannot use var or function as a variable name.)
You can also use the var keyword to declare multiple variables in one statement. For example, the following code declares three variables in one statement:
var price=2020, quantity=3, totalPrice;
totalPrice = price * quantity;
var myName = “Brian”;
console.log(“Hello, ” + myName + “!”); // Outputs: Hello, Brian!
As you can see, using variables can make our code much simpler and more flexible. We could easily change the value of myName to something else and our code would still work just fine. Try it yourself!