Hi all I'm learning javascript and have run into a problem when defining a function in head utilizing imported functions:
<script type="module">
import {g1} From './scripts/main.js';
myFunction(){
do something, g1 is called
}
</script>
when I call myFunction in body I get a myFunction() not defined error:
<script>
myFunction();
</script>
My understanding is this should work, am I making a mistake with the type attribute in head?
In JS the scope of a given code is executed simply like so:
(1) Global scope > (2) Module scope and then the > (3) Function scope
Meaning that you try to access a module scope variable/function in the global scope, you need to restructure you code someway. Your options are: