0

Suppose I have the first.js file where I declared and initialized the array with valid value.

var arrVar = document.getElementsByTagName("label");

I want to use this variable "arrVar" in second.js file. How can I acheive this?

I tried adding below statment in the second.js file at the beginning.

<script type="text/javascript" src="/first.js"></script>

But I am getting error "Unexpected Token <"

cpp_learner
  • 254
  • 1
  • 3
  • 13

1 Answers1

3

You can't add HTML tags into JavaScript files.

And as long as arrVar has been defined in the global scope (not inside any function), it should be accessible in any other file, as it is a global variable.

Oscar Paz
  • 16,845
  • 3
  • 21
  • 36