change global variable value inside function javascript code example
Example 1: create global variable inside function JavaScript
<script>
function foo() {
window.yourGlobalVariable = ...;
}
</script>
Example 2: change a variable outside a function js
var global = "Global Variable"; //Define global variable outside of function
function setGlobal(){
global = "Hello World!";
};
setGlobal();
console.log(global); //This will print out "Hello World"