Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda