JS Built-ins
ObjectObjectbeginner

Object() β€” wrap a primitive value

πŸ“– Usage Example
// Wrap a value in an Object wrapper
const obj = new Object(42)
typeof obj   // β†’ 'object'
obj.valueOf()  // β†’ 42

Use the Object constructor to explicitly wrap a primitive value in an object.

Object() wrapping primitives

When called as Object(value) with a primitive, it returns the boxed wrapper object (e.g. a Number object for numbers).

Challenge: Implement wrapValue(val) that uses Object(val) to wrap a primitive and returns the result.

typeof Object(42)     // β†’ 'object'
typeof Object('hi')   // β†’ 'object'
πŸ’‘ Hints (2)
  • β€’ `Object(42)` creates a `Number` object β€” its `valueOf()` returns the original primitive.
  • β€’ Boxed wrappers are rarely used directly, but this demonstrates the constructor behaviour.