Looking into Underscore.js
code and more specifically into _.indexOf()
function (find code with comments here)
_.indexOf = function(array, item, isSorted) {
var i = 0, length = array && array.length;
if (typeof isSorted == 'number') {
i = isSorted < 0 ? Math.max(0, length + isSorted) : isSorted;
} else if (isSorted && length) {
i = _.sortedIndex(array, item);
return array[i] === item ? i : -1;
}
if (item !== item) {
return _.findIndex(slice.call(array, i), _.isNaN);
}
for (; i < length; i++) if (array[i] === item) return i;
return -1;
};
I noticed the if(item !== item){...}
statement, but I don't get its purpose. items
is a parameter and it's not changed inside the function. When would a variable differ from itself?
Am I missing something?