global
a variable declared outside any function
can be declared with or without var keyword
can be accessed outside or inside any function
E.g.
num = 100;
var salary = 4.5;
can be declared inside a function without using a var keyword
E.g.
function function1() {
// global
firstName = "test";
}
Local
Must be declared inside a function with keyword var
Can NOT be accessed outside the function in which it is declared
E.g.
function function1() {
// local
var firstName = "test";
}
function function1() {
console.log("inside function1");
}
// function alias
var myFunction1 = function1;
myFunction1();
var multiply = function(p1, p2) {
console.log("p1 * p2 = " + (p1 * p2));
}