Skip to content

Conversation

jweboy
Copy link

@jweboy jweboy commented Apr 9, 2018

I think that using == to determine that undefined is not logically rigorous should be replaced by === ==


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.

@jweboy
Copy link
Author

jweboy commented Apr 17, 2018

Then I think that excluding undefined and null is more explicit here, replacing == with ===.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants