Skip to content

@technobuddha > library > Object > Conversion

Function: toString()

ts
function toString(value: unknown): string;

Defined in: to-string.ts:18

Converts an unknown value to its string representation.

  • Returns an empty string if the value is null or undefined.
  • Returns the value itself if it is a string.
  • Converts booleans to 'true' or 'false'.
  • Converts symbols and bigints using their respective toString methods.
  • Returns a string representation for functions in the format function <name>();.
  • Converts numbers using their toString method.
  • For all other types, returns the result of Object.prototype.toString.

Parameters

ParameterTypeDescription
valueunknownThe value to convert to a string.

Returns

string

The string representation of the input value.