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

92
Vistas
How to use the same variable in 2 Javascript files and modify it

I want to use the same variable in 2 javascript files modify it in both files and get the updated value to both files. I tried this. But it doesn't worked.

first.js

let marks = 0;

function func1() {
    function add() {
        marks = marks + 5;
        alert(marks);
        window.location.replace("second.html");
    }
    return {
        add:add;
    }
}

export default func1;

second.js

import func1 from '../first';
func1().add();

function func2() {
    function add2() {
        marks = marks + 5;
        alert(marks);
        window.location.replace("third.html");
    }
    return {
        add2:add2;
    }
}

export default func2;
about 4 years ago · Juan Pablo Isaza
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