how to declare global variable in js across files code example

Example 1: javascript global variable across files

var window.iAmGlobal = "some val"; //Global variable declaration with window.
 
//Any place in other part of code
 
function doSomething()
{
    alert(window.iAmGlobal); //I am accessible here too !!
    //OR
    alert(iAmGlobal); //I am accessible here too !!
}

Example 2: javascript define 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";