how to use a variable outside of a function javascript code example
Example 1: 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 2: change a variable outside a function js
var global = "Global Variable";
function setGlobal(){
global = "Hello World!";
};
setGlobal();
console.log(global);
Example 3: global scope js
const color = 'blue'
const returnSkyColor = () => {
return color;
};
console.log(returnSkyColor());