Node.js | util.types.isBoxedPrimitive() Method

The util.types.isBoxedPrimitive() method is an inbuilt application programming interface of util module which is primarily designed to support the needs of Node.js own internal APIs.

The util.types.isBoxedPrimitive() method is used to check if the given value is a boxed primitive or not.

Syntax:

util.types.isBoxedPrimitive( value )

Parameters: This function accepts one parameter as mentioned above and described below:

  • value: It is the value that would be checked for a boxed primitive.

Return Value: It returns a boolean value i.e true if the passed value is a boxed primitive otherwise returns false.



Below examples illustrate the util.types.isBoxedPrimitive() method in Node.js:

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the    
// util.types.isBoxedPrimitive() method
  
// Import the util module
const util = require('util');
  
// Checking an unboxed string
let unboxedString = "GeeksforGeeks";
console.log("Value:", unboxedString);
isBoxed = util.types.isBoxedPrimitive(unboxedString);
console.log("Value is a boxed primitive:", isBoxed);
  
// Checking a boxed string
let boxedString = new String("GeeksforGeeks");
console.log("Value:", boxedString);
isBoxed = util.types.isBoxedPrimitive(boxedString);
console.log("Value is a boxed primitive:", isBoxed);
  
// Checking an unboxed integer
let unboxedInteger = 99;
console.log("Value:", unboxedInteger);
isBoxed = util.types.isBoxedPrimitive(unboxedInteger);
console.log("Value is a boxed primitive:", isBoxed);
  
// Checking a boxed integer
let boxedInt = new Number(99);
console.log("Value:", boxedInt);
isBoxed = util.types.isBoxedPrimitive(boxedInt);
console.log("Value is a boxed primitive:", isBoxed);
  
// Checking an unboxed boolean
let unboxedBool = false;
console.log("Value:", unboxedBool);
isBoxed = util.types.isBoxedPrimitive(unboxedBool);
console.log("Value is a boxed primitive:", isBoxed);
  
// Checking a boxed boolean
let boxedBool = new Boolean(false);
console.log("Value:", boxedBool);
isBoxed = util.types.isBoxedPrimitive(boxedBool);
console.log("Value is a boxed primitive:", isBoxed);

chevron_right


Output:

Value: GeeksforGeeks
Value is a boxed primitive: false
Value: [String: 'GeeksforGeeks']
Value is a boxed primitive: true
Value: 99
Value is a boxed primitive: false
Value: [Number: 99]
Value is a boxed primitive: true
Value: false
Value is a boxed primitive: false
Value: [Boolean: false]
Value is a boxed primitive: true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the    
// util.types.isBoxedPrimitive() method
  
// Import the util module
const util = require('util');
  
// Checking for the symbol primitive
let symbol = Symbol('geeks');
console.log("Value:", symbol);
isBoxed = util.types.isBoxedPrimitive(symbol);
console.log("Value is a boxed primitive:", isBoxed);
  
// Checking again after creating a symbol wrapper
let symbolObj = new Object(Symbol('geeks'));
console.log("Value:", symbolObj);
isBoxed = util.types.isBoxedPrimitive(symbolObj);
console.log("Value is a boxed primitive:", isBoxed);

chevron_right


Value: Symbol(geeks)
Value is a boxed primitive: false
Value: [Symbol: Symbol(geeks)]
Value is a boxed primitive: true

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




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.