The problem of variable exposure in node

first a.js:

var x;
exports.x = x;
console.log (x) / / 123

second b.js:

var a = require (". / a.js");
setTimeout (function () {console.log (a.x)}, 1000);

run b.js and output undefined,. Why? Haven"t you already been exposed?

Jun.16,2021

where does a.js assign a value to x? Please post the complete code


you didn't assign a value to x. Why is there 123? Is there any other place to introduce
?

put aside the above two questions, then mine is right.

clipboard.png


a.js does not assign x, and consolo.log (x) should be undefined

.
Menu