[ACCEPTED]-How can I use a variable of one <script> in another <script> in javascript?-global

Accepted answer
Score: 16

If the two script tags are on the same page, any 2 variable declared outside of the scope of 1 a function is global to the page.

Score: 10

Make it global;

script1.js

 var foobar = "O HAI";

script2.js

  alert(foobar);

0

Score: 6

If the two script tags are on the same page, any 4 variable declared outside of the scope of 3 a function is global to the page. However, it 2 does matter which script is loaded first 1 for some applications.

Score: 0

When you declared a variable inside a <script> , you 1 can access it anywhere simply by using this:

var myValue= window.yourProperty;

More Related questions