Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

93
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!