Global variables in Javascript across multiple files

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.

<script type="text/javascript" > 
  var myFunctionTag = false; 
</script>
<script type="text/javascript" src="https://stackoverflow.com/questions/2932782/js/helpers.js"></script>     
... 
<script type="text/javascript" > 
  // rest of your code, which may depend on helpers.js
</script>

Leave a Comment