Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda