1window.myGlobalVariable = "I am totally a global Var"; //define a global variable
2var myOtherGlobalVariable="I too am global as long as I'm outside a function";
1<script>
2function foo() {
3 window.yourGlobalVariable = ...;
4}
5</script>
1If you trying to acess a variable from a function
2then,
3let i=0;
4function as(){
5 i=1 ///global variable
6}
7as()
8console.log(i)
9const d=()=>{
10 console.log("from d: ",i)
11}
12d()
13the output
141
15from d : 1
16
17better way is window.myGlobalVariable = "your variable"
18not encourged to use global variable at all