Scope js code example
Example 1: scope.js
var a = 20;
console.log(a);
if(true){
var a = 50;
console.log(a);
}
function callMe(){
var a = 100;
console.log("Inside call me");
console.log(a);
}
callMe();
console.log(a);
Example 2: javascript define global variable
window.myGlobalVariable = "I am totally a global Var";
var myOtherGlobalVariable="I too am global as long as I'm outside a function";
Example 3: global scope js
const color = 'blue'
const returnSkyColor = () => {
return color;
};
console.log(returnSkyColor());