Facebook Pixel

Object.assign()

JavaScript
medium
15 mins

The Object.assign() method copies all enumerable own properties from one or more source objects to a target object. It returns the modified target object. Your task is to replicate this functionality.

  • If the target is null or undefined, throw a TypeError.
  • Only enumerable and own properties should be copied.
  • Later source properties overwrite earlier ones if they have the same key.
  • The method should return the target object.

Example Inputs & Outputs

customAssign({a: 1}, {b: 2}) β†’ {a: 1, b: 2} customAssign({a: 1}, {a: 2, b: 3}) β†’ {a: 2, b: 3} customAssign({}, {a: undefined}, {b: null}) β†’ {a: undefined, b: null}

Constraints & Edge Cases

  • target must not be null or undefined
  • Only own, enumerable properties of source objects should be copied
  • If a source is null or undefined, it should be skipped (not throw an error)
  • Must return the modified target object
  • Symbol properties should be ignored in this simplified version

Solve Similar questions πŸ”₯

Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.