Skip to content

getType

The getType function returns a string representing the type of the provided value, including special cases like "nan", "infinity", "null", and "array".

Syntax

typescript
getType(value: any): string;

Parameters

ParameterTypeDescription
valueanyValue to be inspected

Returns

TypeDescription
stringValue type (e.g., "string", "array", "nan")

Examples

typescript
getType([]); // => "array"
getType(null); // => "null"
getType(NaN); // => "nan"
getType(Infinity); // => "infinity"
getType(123); // => "number"

Notes

  • Useful for identifying value types, including special cases.

References

Released under the MIT License.