Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double underscore vs single underscore in nodeJS

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.

like image 314
chaudharyp Avatar asked Dec 07 '22 23:12

chaudharyp


1 Answers

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.

like image 105
SuRa Avatar answered Dec 11 '22 10:12

SuRa