Saturday, March 23, 2019

scope - Global variables in Javascript across multiple files



A bunch of my JavaScript code is in an external file called helpers.js. Inside the HTML that calls this JavaScript code I find myself in need of knowing if a certain function from helpers.js has been called.



I have attempted to create a global variable by defining:



var myFunctionTag = true;



In global scope both in my HTML code and in helpers.js.



Heres what my html code looks like:




...

...




Is what I am trying to do even feasible?


Answer



You need to declare the variable before you include the helpers.js file. Simply create a script tag above the include for helpers.js and define it there.






...



No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...