Answers for "assign value to global variable in javascript"

33

javascript define global variable

window.myGlobalVariable = "I am totally a global Var"; //define a global variable
var myOtherGlobalVariable="I too am global as long as I'm outside a function";
Posted by: Guest on August-02-2019
0

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"
Posted by: Guest on September-12-2020
1

how to global a variable in javascript

globalThis.yourGlobalVariable = ...;
Posted by: Guest on November-21-2021

Code answers related to "assign value to global variable in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language