Why isn't my javascript working

What's the context ?

"works <-> doesn't"

What, if any, are the error messages ?
What kind of value are you trying to obtain ?

I think you would have to post a full KM example to make it clear what is really being evaluated, and in what interpreter and browser context.


In the meanwhile, you will get more helpful error messages, and a temporary local namespace, rather than a global one which persists between script runs, if you enclose your code in a "use strict" IIFE context.

If you have bound the name iFrame with let or const in a global namespace in one script run, then it will remain defined (unavailable for redefinition) in the next script run.

Polluting the global namespace is never a good plan.


(() => {
    "use strict";

    // Code to evaluate here, in the temporary namespace
    // roped off by an Immediately Invoked Function Expression
    // ...
})()

See: