Answers for "javascript define a global variable"

29

javascript define a 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
-1

javascript global function

window.my_function = function(){
	//
}
Posted by: Guest on June-12-2020
0

global variable in js

If you trying to acess a variable from a function
then,
let i=0;
function as(){
   i=1 ///global variable
}
as()
console.log(i)
const d=()=>{
  console.log("from d: ",i)
}
d()
the output
1 
from d : 1

better way is window.myGlobalVariable = "your variable"
not encourged to use global variable at all
Posted by: Guest on March-09-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language