JS Built-ins
← String186 / 195
StringString.prototype.valueOfbeginner

String.prototype.valueOf() β€” returns primitive string

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

Use valueOf() to return the primitive string value, useful when working with String wrapper objects.

String.prototype.valueOf()

str.valueOf() returns the primitive string value of a String object or primitive.

Challenge: Implement getValueOf(str) that calls .valueOf() and returns the result.

getValueOf('hello') // β†’ 'hello'
πŸ’‘ Hints (1)
  • β€’ For a primitive string, `valueOf()` returns the string itself.