JS Built-ins
← Object148 / 150
ObjectvalueOfbeginner

valueOf() β€” Boolean valueOf

πŸ“– Usage Example
// Retrieve the primitive value of an object
const n = new Number(42)
n.valueOf()   // β†’ 42
const obj = { valueOf() { return 10 } }
obj + 5       // β†’ 15

Use valueOf() to retrieve the underlying primitive value of an object; JavaScript calls it automatically in numeric contexts.

valueOf() β€” Boolean

Boolean wrapper objects have a valueOf() that returns the wrapped primitive boolean value.

Challenge: Verify that Boolean's valueOf returns a boolean primitive.

πŸ’‘ Hints (1)
  • β€’ Boolean wrapper objects are always truthy; use valueOf to get the primitive