variable global 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: create global variable inside function JavaScript
<script>
function foo() {
window.yourGlobalVariable = ...;
}
</script>
Example 3: global scope js
const color = 'blue'
const returnSkyColor = () => {
return color;
};
console.log(returnSkyColor());
Example 4: javascript global function
window.my_function = function(){
}