Variables in JavaScript
VARIABLES IN JAVASCRIPT
Like many other programming languages, JavaScript has variables. JavaScript variables are containers for storing data values. Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container.
Before you use a variable in a JavaScript program, you must declare it. Variables are declared with the var keyword as follows:
var name; var number;
You can also declare multiple variables with the same var keyword as follows:
var name, number;
You can also declare variables with let and const keyword as follows:
let name; const number;
You can assign a value to a variable using assignment (=) operator.
var x = 5; var y = 6; var z = x + y; var myName = "Kenny";
JavaScript variable names are made up of letter, numbers and underscores. These unique names are called identifiers. Identifiers can be short names (like i ,y and x) or more descriptive names (name, sum, totalMoney).JavaScript identifiers are case-sensitive. JavaScript variable names can be of any length (but don't make it too long).
The general rules for constructing names for variables are:
Names can contain letters, digits, underscores, and dollar signs.
Names must begin with a letter.
Names can also begin with $ (dollar) and _ (underscores).
They cannot contain spaces and must not begin with a number.
Names are case sensitive (y and Y are different variables).
var $ = 5; var _name = "kunle";
JavaScript has two scopes- global and local. Any variable declared outside of a function belongs to the global scope, and is therefore accessible from anywhere in your code. Each function has its own scope, and any variable declared within that function is only accessible from that function (local scope).
JavaScript variables can hold many data types: numbers, strings, boolean, objects and more.
String : A string (or a text string) is a series of characters like "Peter Rocks".Strings are written with quotes. You can use single or double quotes.
var name ="Peter"; var name = 'Peter';
Number : JavaScript has only one type of numbers.Numbers can be written with, or without decimals.
var x = 345; var y = 8.89;
If you put a number in quotes, it will be treated as a text string.
var num = "345" // this is not a number but a string
Boolean : Boolean can only have two values: true or false. Boolean are often used in conditional testing.

