I need a few global variables that I need in all .js files.
For example, consider the following 4 files:
global.jsjs1.jsjs2.jsjs3.js
Is there a way that I can declare 3 global variables in global.js and access them in any of the other 3 .js files considering I load all the above 4 files into a HTML document?
Can someone please tell me if this is possible or is there a work around to achieve this?
Just define your variables in global.js outside a function scope:
To make sure that this works you have to include/link to global.js before you try to access any variables defined in that file:
You could, of course, link in the script tags just before the closing <body>-tag if you do not want the load of js-files to interrupt the initial page load.