Phillip Senn
Phillip Senn

Reputation: 47595

JavaScript naming conventions with underscore

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?

Upvotes: 0

Views: 1063

Answers (2)

gen_Eric
gen_Eric

Reputation: 227240

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 _.

Upvotes: 3

Quentin
Quentin

Reputation: 943510

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.

Upvotes: 4

Related Questions