define global function in javascript code example
Example: 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