0

In browsers global variables are actually properties of window object.

If I declare a variable with var keyword in Node.js then will it be a property of module object?

var aaa = 'aaa';
console.log(module.aaa); // undefined

Why is it undefined? Doesn't module object in Node.js follow the same logic as global object in browsers?

1 Answer 1

2

will it be a property of module object?

No, and that explains why it is undefined. Anything defined inside a module is enclosed in that module unless exposed explicitly via exports or module.exports.

Sign up to request clarification or add additional context in comments.

1 Comment

So it will be like a "normal" local variable? Like local variables in functions that aren't properties of any object? Just to make sure I understand correctly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.