-3

Say I have the following code in my HTML body:

<script src = "first.js"></script>
<script src = "second.js"></script>

So in first.js I have two variables declared in a global scope. Why can't I access them from second.js?

1 Answers1

0

The following code works as expected. Without being able to see all your relevant code it's impossible to diagnose your issue. That's why you're being downvoted.

index.html

<script src="first.js"></script>
<script src="second.js"></script>
<script>
  console.log(firstGlobal, secondGlobal); // true true
</script>

first.js

var firstGlobal = true;

second.js

var secondGlobal = true;
GirkovArpa
  • 4,427
  • 4
  • 14
  • 43