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

String.prototype.toString() β€” primitive string

πŸ“– 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()

str.toString() returns the string value. For a primitive string, it returns the same value.

Challenge: Implement stringValue(str) that calls .toString() and returns the result.

stringValue('hello') // β†’ 'hello'
πŸ’‘ Hints (1)
  • β€’ For primitive strings, `toString()` simply returns the string itself.