Question: I would like to know how to pass the value of a variable in JavaScript file to a variable in a script function which is written on top of the HTML file.

I wrote it like this:

*myjsfile.js*:

```
var abc = "10";

```

*HTML file*:

```
<html>
<head>
<script type="text/javascript">
(function() {

var test = document.createElement('script'); test.type = 'text/javascript'; test.async = true;

test.src = 'testquery.js';

var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(test, s);

alert(abc);
})();

</script>
</head>
<body>
</body>
</html>

```

I am not getting the output. Please help! Thanks in advance.

Basically I am trying to create a jquery plugin just like Google analytics.

Answer: 
The script has to load first, try using `onload`

```
test.onload=function(){alert(abc);}

```
```
<html>
  <head>
    <script type="text/javascript" src="testquery.js"></script>
    <script type="text/javascript">
        alert(abc);
    </script>
 </head>
 <body></body>
</html>

```