-1

I'm trying sublet big single source code to small modules. I want to use same variable name on each jsfile. But them are required on mainjs file.

Does it makes any problem?

main.js

require('./module1');
require('./module2');

module1

let obj = new Something();

module2

let obj = new Something();
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
JunheePark
  • 35
  • 7

1 Answers1

0

Each module is a separate entity and you can use same variables in different modules. But not same variables in a single module. By means of a separate entity is that stack of variables are maintained separately for each module when its complied.

  • If we import all these modules that share the same variable name into for example index.js, how would that play out? – yamanidev Sep 29 '21 at 16:56