JS Built-ins
← String160 / 195
StringString.prototype.toStringbeginner

String.prototype.toString() β€” explicit call

πŸ“– Usage Example
const str = 'Hello'
str.toString()              // β†’ 'Hello'
new String('hi').toString()  // β†’ 'hi'

Use toString() to return the primitive string value of a string or String object.

String.prototype.toString() β€” Explicit Call

You can call .toString() explicitly to ensure you have a string primitive.

Challenge: Implement explicitToString(str) that calls toString and checks the type.

explicitToString('42') // β†’ 'string'
πŸ’‘ Hints (1)
  • β€’ `typeof str.toString()` is always `"string"` for string primitives.