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

Node.jsServer Side ProgrammingProgramming

The util.types.isBoxedPrimitive() method checks whether the passed value is a built-in Primitive object or not. If the above condition is satisfied, it returns True, else False. Primitive object includes new Boolean(), new String() or Object(Symbol()).

Syntax

util.types.isBoxedPrimitive(value)

Parameters

  • value − This input value takes input for the required parameter and checks if it's a Float32-Array instance or not.

It returns True or False based upon the input value passed.

Example 1

Create a file with the name "isBoxedPrimitive.js" and copy the following code snippet. After creating the file, use the command "node isBoxedPrimitive.js" to run this code.

// util.types.isBoxedPrimitive() Demo Example

// Importing the util module
const util = require('util');

// Passing boolean as variable
console.log("1." + util.types.isBoxedPrimitive(false));

// Passing boolean value as primitive object
console.log("2." + util.types.isBoxedPrimitive(new Boolean(false)));

// Passing 'foo' as a value
console.log("3." + util.types.isBoxedPrimitive(Symbol('foo')));

// passing 'foo' as an object
console.log("4." + util.types.isBoxedPrimitive(Object(Symbol('foo'))));

Output

C:\home\node>> node isBoxedPrimitive.js
1.false
2.true
3.false
4.true

Example 2

// util.types.isFloat32Array() Demo Example

// Importing the util module
const util = require('util');

var float32 = new Float32Array(2);
float32[0] = 21;

var stringObj = new String('Welcome to Tutorials Point')

var bigInt = Object(BigInt(5));

// Passing float32 object as input
console.log("1." + util.types.isBoxedPrimitive(float32));

// Passing String object
console.log("2." + util.types.isBoxedPrimitive(stringObj));

// Passing a BigInt object
console.log("3." + util.types.isBoxedPrimitive(bigInt));

Output

C:\home\node>> node isBoxedPrimitive.js
1.false
2.true
3.true
raja
Published on 17-Aug-2021 11:11:17
Advertisements