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

336
Vistas
In Javascript, is there a way to call a var in another .js file like in Java?

In Java if I wanna call a var from another file in the same folder I can just call the file name and then the var I wanna call. But, I'm looking for a similar thing in Javascript. Please let me know if there is. For Example:

FileName: wordBank.java

int wordCount = 0;

Then in the Other File I can call that wordCount by saying:

wordBank.wordCount = 1; // (assuming wordCount is public)

So is there a way to mimic this code in Javascript?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have to explicitly export and import it like so with es6 wordBank.js:

export const wordCount = 0;

otherFile.js:

import { wordCount } from "./wordBank"
console.log(wordCount)

However, there is no specific way to outright mutate a variable passes between files. You could do something like this:

let wordCount = 0;
export function setWordCount(value) {
    wordCount = value
}

then in the other file:

import { setWordCount } from "./wordBank"

setWordCount(1)
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