Underscore.js _.isString()
The _.isString() function is used to check whether the given object element is string or not.
Syntax:
_.isString( object );
Example: This example shows the implementation of above-explained appraoch.
let _ = required("underscore");
let info = {
Company: 'w3wiki',
Address: 'Noida',
Contact: '+91 9876543210'
};
console.log(_.isString(info));
let str = 'w3wiki';
console.log(_.isString(str));
Output:
false
true
Check if a variable is a string using JavaScript
In this article, we will check if a variable is a string using JavaScript. We can check the variable by using many methods.
Below are the following methods through which we can check the type of variable is a string:
Table of Content
- Using typeOf Operator
- Using Instanceof Operator
- Underscore.js _.isString()
- Using Lodash _.isString() Method
- Using Object.prototype.toString.call Method
Contact Us