Node.js util.types.isExternal() Method
The util.types.isExternal() method is an inbuilt application programming interface of the util module which is used to check if the value is a native External value in the node.js.
Syntax:
util.types.isExternal( value )
Parameters: This method accepts a single parameter as mentioned above and described below.
- value: It is a required parameter of any datatype.
Return Value: This returns a boolean value, TRUE if the value is a native External value, FALSE otherwise.
The below examples illustrate the use of util.types.isExternal() method in Node.js:
Example 1:
Javascript
const util = require( 'util' );
const v1 = new Date();
const { JSStream } = process.binding( 'js_stream' );
const external = ( new JSStream())._externalStream;
console.log(util.types.isExternal(v1));
console.log(util.types.isExternal(external));
console.log(util.types.isExternal(0));
console.log(util.types.isExternal( new String( 'foo' )));
|
Output:
false
true
false
false
Example 2:
Javascript
const util = require( 'util' );
const v1 = new Date();
const { JSStream } = process.binding( 'js_stream' );
const ext = ( new JSStream())._externalStream;
const str = new String( 'Geeks' )
if (util.types.isExternal(v1))
console.log( "It is a native External value." );
else
console.log( "It is not a native External value." );
if (util.types.isExternal(ext))
console.log( "It is a native External value." );
else
console.log( "It is not a native External value." );
if (util.types.isExternal(0))
console.log( "It is a native External value." );
else
console.log( "It is not a native External value." );
if (util.types.isExternal(str))
console.log( "It is a native External value." );
else
console.log( "It is not a native External value." );
|
Output:
It is not a native External value.
It is a native External value.
It is not a native External value.
It is not a native External value.
Reference: https://nodejs.org/api/util.html#util_util_types_isexternal_value
Last Updated :
31 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...