Why lodash .isNumber function is more complicated than typeof value == 'number'

Viewed 10344
2 Answers

From your link:

Checks if value is classified as a Number primitive or object.

var n = new Number(3);
console.log(typeof n); // "object"
console.log(_.isNumber(n)); // true

MDN - Number:

The Number JavaScript object is a wrapper object allowing you to work with numerical values. A Number object is created using the Number() constructor. A primitive type object number is created using the Number() function.

While the Number() function will create a number primitive, the Number() constructor will create a Number object:

typeof Number(0) // 'number'
typeof new Number(0) // 'object'

Lodash checks for both cases.

Related