Global variables in Javascript across multiple files

Posted by Goro on Stack Overflow See other posts from Stack Overflow or by Goro
Published on 2010-05-28T21:54:57Z Indexed on 2010/05/29 0:12 UTC
Read the original article Hit count: 232

Filed under:
|

Hello,

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:

<html>
...
<script type='text/javascript' src='js/helpers.js'></script>    
...
<script>
  var myFunctionTag = false;
  ...
  //I try to use myFunctionTag here but it is always false, even though it has been se t to 'true' in helpers.js
</script>

Is what I am trying to do even doable?

Thanks,

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about web-development