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

268
Visualizações
How to use variable from one .js file in another .js

I am trying to create a website with html and jquery. I have data.js (with const travelInfoURL = '<url>';) file with the url I need. I want to use it in main.js file, but I am getting the following error:

main.js:130 Uncaught ReferenceError: travelInfoURL is not defined

How to solve this issue? I tried to export the travelInfoURL in data.js (export{travelInfoURL};), but it didn't help. The files are located in the same directory.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It's hard to answer this question without knowing the JS runtime that is being used, but your question indicates you are at least using ES6 import/export syntax.

Your question does not indicate that you are importing what you are exporting. If you want to export travelInfoURL not as the default export of the file, you can do so by writing:

export const travelInfoURL  = '<url>';
In the other file you can import this as:
import { travelInfoURL } from './main';
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