How to change variables across different modules or js files?

I am in the process of seperating my code so it is more clean. I have started doing this by putting my functions in their respective module. So instead of keeping it in the "index.js", I am keeping it in "change.js" (example name). Here is my function:

let number = 5;

function change(){
    number = number + 1;

The problem is, when I put this function in its own respective module called "change.js", when it is called, it gives the error that the variable "number" is not declared. If I then declare it in the "change.js" file, the variable "number" only changes in that file and not in "index.js". Is there anyway to change it in both files, or transfer the value from "change.js" to "index.js"?

72 thoughts on “How to change variables across different modules or js files?”

  1. i need personal loan urgent, i need a loan help please. i need a payday loan direct lender i need loan need a loan been refused everywhere i need a loan with no credit check, cash advance loans till payday, cash advance loans, cash advances, cash advance payday loans. Financial affairs lending to business, designed for companies.


Leave a Comment