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

The util.types.isStringObject() method of the util module is primarily designed to support the needs of Node.js own Internal APIs. It is used to check whether the passed instance in the method is a String object or not. There is difference between string primitive and String object in javascript, string is a primitive datatype it has no methods and it is nothing more than a pointer to a raw data memory reference.

Syntax:

util.types.isStringObject( value )

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

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

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



Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the    
// util.types.isStringObject() method 
    
// It includes util module 
const util = require('util'); 
    
// Return false as passed value is
// a string but not a String object 
console.log(util.types.isStringObject("geeksforgeeks")); 
    
// Return true as passed value is String object
console.log(util.types.isStringObject(new String())); 

chevron_right


Output:

false
true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Node.js program to demonstrate the    
// util.types.isStringObject() method 
    
// It includes util module 
const util = require('util'); 
  
//temp_string is a primitive datatype
var temp_string = "geeksforgeeks"
    
// Return false as passed value is a
// string but not a String object 
console.log(util.types.isStringObject(temp_string)); 
    
//making string into String object
var s_object = new String(temp_string);
  
// Return true as passed value is a string
// but not a String object 
console.log(util.types.isStringObject(s_object));
  
//Return false as passes value is not a String object
console.log(util.types.isStringObject(new Set()));

chevron_right


Output:

false
true
false

Reference: https://nodejs.org/api/util.html#util_util_types_isstringobject_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.