In this SO question, the answerer uses an underscore on line 3. If it were simply the start of a variable name, I'd be good with that. But what does _(row) mean?
Asked
Active
Viewed 909 times
0
-
I think this is PHP. But I may be wrong – ControlAltDel May 02 '12 at 20:51
-
2the question is answered right in his post and you commented on it. What's the point of posting this? – Cfreak May 02 '12 at 20:51
-
Oh, I see. It's another JavaScript library called underscore. – Phillip Senn May 02 '12 at 20:53
2 Answers
4
It is the start of a variable name. It is also the end of a variable name. The variable (which has a function assigned to it) is _
. The question references underscore.js, which provides it.
Try, for example:
function _() {
alert('underscore!');
};
console.log(typeof _);
console.log(_);
_();
Welcome to the wonderful world of completely unintuative variable names that are used because they are short and not alphanumeric. See also $
, beloved of Prototype, jQuery and Mootools. In counterpoint, see Self-documenting (code) on Wikipedia.

Quentin
- 914,110
- 126
- 1,211
- 1,335
-
Thanks Quentin! I've heard of the underscore library in passing, but have never taken the time to read anything about it. – Phillip Senn May 02 '12 at 21:18
3
The _
is underscore.js
. _
is a variable, it's a function, so you can do _(rows)
.
In JavaScript, you can name variables whatever you want. Such as $
(jQuery) and _
.

gen_Eric
- 223,194
- 41
- 299
- 337
-
OK, thanks Rocket! If I have jQuery loaded, I don't think I need underscore. It looks like I can process it with the jQuery each command. – Phillip Senn May 02 '12 at 21:19