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 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.
Below examples illustrate the use of util.types.isExternal() method in Node.js:
Example 1:
Javascript
// Node.js program to demonstrate the // util.types.isExternal() Method // Allocating util module const util = require( 'util' ); // Value to be passed as parameter // of util.types.isExternal() method var v1 = new Date(); const { JSStream } = process.binding( 'js_stream' ); const external = ( new JSStream())._externalStream; // Printing the returned value from // util.types.isExternal() method 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
// Node.js program to demonstrate the // util.types.isExternal() Method // Allocating util module const util = require( 'util' ); // Value to be passed as parameter // of util.types.isExternal() method var v1 = new Date(); const { JSStream } = process.binding( 'js_stream' ); const ext = ( new JSStream())._externalStream; var str = new String( 'Geeks' ) // Calling // util.types.isExternal() method 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
Please Login to comment...