JS Built-ins
ObjectObjectintermediate

Object(obj) β€” returns the same reference

πŸ“– 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() with an existing object

When you pass an existing object to Object(obj), it returns the same reference β€” it does not create a copy.

Challenge: Implement identityWrap(obj) that passes obj through Object() and returns the result.

const o = { a: 1 }
identityWrap(o) === o // β†’ true
πŸ’‘ Hints (2)
  • β€’ When the argument is already an object, `Object(obj)` returns the same reference unchanged.
  • β€’ This is different from `Object.assign({}, obj)` which creates a shallow copy.