Skip to content
Related Articles

Related Articles

Improve Article

Node.js util.types.isNumberObject() Method

  • Last Updated : 13 Oct, 2021
Geek Week

The util.types.isNumberObject() method of util module is primarily designed to support the needs of Node.js own Internal APIs. It is used to check whether the passed value is a Number object or not.

Syntax

util.types.isNumberObject( value )

Parameters: This method accepts a single parameter value which holds any number i.e. instance of any module.

Return value: This method returns a Boolean value i.e true if the passed value is a Number object otherwise returns false.

Below examples illustrate the use of util.types.isNumberObject() method in Node.js:



Example 1:




// Node.js program to demonstrate the   
// util.types.isNumberObject() method
  
// It includes util module
const util = require('util');
  
// Returns false as it is not a number object
console.log(util.types.isNumberObject(0));
  
// Returns true as it is a number object
console.log(util.types.isNumberObject(new Number(0)));

Output:

false
true

Example 2:




// Node.js program to demonstrate the   
// util.types.isNumberObject() method
  
// It includes util module
const util = require('util');
  
// Returns false becaluse it is not a number object
console.log(util.types.isNumberObject(100));
  
// Returns true because it is a number object
console.log(util.types.isNumberObject(new Number(12345678)));
  
// returns false because it is not a number object
console.log(util.types.isNumberObject(1.8));
  
// Returns true because it is a number object
console.log(util.types.isNumberObject(new Number(1.8)));
  
// Returns false as Number() method just convert
// string to number not to Number Object
console.log(util.types.isNumberObject(Number('1.8')));

Output:

false
true
false
true
false

Reference: https://nodejs.org/api/util.html#util_util_types_isnumberobject_value




My Personal Notes arrow_drop_up
Recommended Articles
Page :