I have encountered 2 conflicting naming conventions while using nodeJS. Some variables start with a single underscore, like _temp
, while some start with double underscore, like __dirname
.
I have been trying to search for an answer to this naming convention difference. I checked out Double Underscore in front of a variable but the answer was very specific to __dirname
and __filename
. It didn't address the conflicting naming convention.
It will be great if someone could provide me with a resource for this.
Even I am new to node.js and searching for the answer. Found the answer in node.js documentation. Refer Node.js - Globals for more details.
As mentioned above answer, variable with single underscore (_private) is to define private variable.
Double underscore (__) is not of any convention in node.js. There were only two variables (called global objects) with double underscores in node.js.
__dirname : used when to get the name of the directory that the currently executing script resides in.
__filename : used to get the filename of the code being executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With