Skip to main content

Check if a value is a string

JavaScript version

const isString = (value) => Object.prototype.toString.call(value) === '[object String]';

TypeScript version

const isString = (value: any): boolean => Object.prototype.toString.call(value) === '[object String]';

Examples

isString('hello world'); // true
isString(new String('hello world')); // true
isString(10); // false

Comments