window.myGlobalVariable = "I am totally a global Var"; //define a global variablevar myOtherGlobalVariable="I too am global as long as I'm outside a function";
global variable in js
If you trying to acess a variable from a function
console.log("from d: ",i)
1from d : 1
better way is window.myGlobalVariable = "your variable"
not encourged to use global variable at all
In this page (written and validated by A. Gawali) you learned about
Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: firstname.lastname@example.org.