Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
Function defined in head not recognized in body?

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?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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:

  • Either to put the code within the same module
  • Or find a way to import one module into the other one
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!