I have two files. I am creating the multiple object of one file into other.
module1.js
var a = 5;
var check1 = function(){
a = a + 10;
console.log(a);
}
exports.check = check1;
module2.js
var c = require('../module1');
var d = require('../module1');
c.check();
d.check();
The output is 15 & 25.
When you declare a variable using var, the scope is local. And i am creating two instances of module.js. So why is it getting declared at global level because the output is 15 & 25?
I need output as 15 & 15 as i want to use this variable as object level variable. What should i do?