JS Built-ins
ObjectObject.assignbeginner

Object.assign() β€” return value is the target

πŸ“– Usage Example
// Merge source into target
const target = { a: 1 }
Object.assign(target, { b: 2 })   // β†’ { a: 1, b: 2 }

Use Object.assign() to copy properties from one or more source objects into a target object.

Object.assign() return value

Object.assign returns the target object, which is the same reference that was passed as the first argument.

Challenge: Implement checkReturnIsTarget(target, source) that calls Object.assign(target, source) and returns whether the result is strictly equal (===) to target.

checkReturnIsTarget({ a: 1 }, { b: 2 }) // β†’ true
πŸ’‘ Hints (2)
  • β€’ `Object.assign` always returns its first argument (the target) β€” it never creates a new object.
  • β€’ Compare with `===` to check reference identity.