Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports = function arrayFirst(arr, num) {
}

var first = slice(arr, 0, isNumber(num) ? +num : 1);
if (+num === 1 || num == null) {
if (+num === 1 || num === undefined) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more rigorous than num === undefined.

var undefined = 'foo';
var val;
console.log(val === undefined) // false
console.log(val == null) // true

This is because undefined can be a defined value, but num == null checks both typeof num === 'undefined' and num === null.

return first[0];
}
return first;
Expand Down