Global this in JavaScript code example
Example 1: 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
Example 2: javascript global function
window.my_function = function(){
//
}