I have seen variables like _ image and was wondering what _ meant?
The underscore prefix is meant as a hint to another programmer that a variable or method starting with a single underscore is intended for internal use.
Variable names can never contain spaces. The underscore character ( _ ) can also appear in a name.
Variable names should not start with underscore ( _ ) or dollar sign ( $ ) characters, even though both are allowed. This is in contrast to other coding conventions that state that underscores should be used to prefix all instance variables. Variable names should be short yet meaningful.
Double underscore (__) in front of a variable is a convention. It is used for global variable (The following variables may appear to be global but are not, rather local to each module) in Nodejs meanwhile Underscore(_) used to define private variable.
It doesn't mean anything. It is rather a common naming convention for private member variables to keep them separated from methods and public properties. For example:
class Foo { private int _counter; public int GetCounter() { return _counter; } public int SetCounter(int counter) { _counter = counter; } }
In most languages _
is the only character allowed in variable names besides letters and numbers. Here are some common use cases:
some_variable
_private
filter_
(since filter
is a built-in function)[0 for _ in range(n)]
Note that some people really don't like that last use case.
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