File js interaction file .js?

help me!

im have 2 file .js
file 1.js code:
document.write(“<script src=2.js></script>”)

file 2.js code:
var f=“hello”

im want run 1.js get variable of file 2.js by 3.html but don’t run!

code 3.html

<script src=1.js></script>

When the document.write code executes, that updates the DOM with the command to bring in 2.js, but the 2.js coe is not yet available. It has to be downloaded and run before you can make use of what’s in there.

You could wait for a long period of time until it’s available, or you can write some code to monitor things so that once the loaded code is available, you can do something.

There are a wide-range of javascript loaders that can do the job for you, or you can use something like this:

function waitFor(trigger, callback) {
    if (trigger()) {
    } else {
        setTimeout(function () {
            waitFor(trigger, callback);
        }, 100);

which you could call with:

waitFor(function () {
    return typeof(f) !== 'undefined';
}, function () {