A JavaScript variable is simply a name of storage location. There are two types of variables in JavaScript : local variable and global variable.
JavaScript Variables are also known as identifiers.
First hand rules when you declare a variable :-
1. JS variables are case sensitive(x and X are different).
2.Name must start with a letter,underscore or dollar sign.
3.After first letter,we can use numbers.(javascript1).
Correct way : -
var x = 10;
var_value = 'Any'
JavaScript local variables :-
A JavaScript local variable is declared inside block or function. It is accessible within the function or block only.
function xyz() {
var a = 10 //local var
}
Global Variables :-
Global variable can be accessible from any function.It is declared outside function or with the window object.
var cat = 2
function xyz() {
console.log(cat) //Console.log is used to log the data inside the console.
}
xyz()
::output : 2
For console go to chrome developer tools(in settings) and go to console from there.(Try to console.log this function)