Determines whether the provided value is a string.
This function returns true if the input is a non-null, non-undefined primitive string. It acts as a type guard, so TypeScript will narrow the type to string when used in conditionals.
true
string
The type of the input value.
The value to be checked.
false
isString("hello"); // trueisString(123); // falseisString(null); // falseisString(undefined); // falseconst value: unknown = "test";if (isString(value)) { console.log(value.toUpperCase());} Copy
isString("hello"); // trueisString(123); // falseisString(null); // falseisString(undefined); // falseconst value: unknown = "test";if (isString(value)) { console.log(value.toUpperCase());}
Determines whether the provided value is a string.
This function returns
true
if the input is a non-null, non-undefined primitive string. It acts as a type guard, so TypeScript will narrow the type tostring
when used in conditionals.