How module works in nodejs?

Let’s create a test.js file and type console.log(arguments), what will return?


  1. undefined
  2. something else, but what? 🙂

the answer is


it is a array of 5 items?

So what are they?

To answer this question, we need to understand how module works in nodejs. Nodejs wraps the module into the function before compiling the modules and that function looks like below. As you can see, the function has 5 parameters, that explains what we saw in the previous picture.


Hard to believe? Let put a break point at console.log(arguments) and debug the code, then you can see the 5 parameters are in the local scope of the current module. Please note, the first line and third line are comments.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s