I'm doing a redux tutorial, and I saw a call like this:
this._render();
and it's defined elsewhere as:
_render() { .... }
What is the underscore "_"? Why is it used?
This is convention of private methods and variables. In JavaScript there is no real privacy of classes.
It means that you should not use these method (starting with "_
") out of your object. Of course technically you can, but "_
" means that you should not.
Underscore (_
) is just a plain valid character for variable/function name, it does not bring any additional feature.
However, it is a good convention to use underscore to mark variable/function as private. You can check Underscore prefix for property and method names in JavaScript for some previous discussion.
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