Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up

Which of these creates a shallow copy of an object?

  1. A const copy = original;
  2. B const copy = {...original};
  3. C const copy = structuredClone(original);
  4. D const copy = Object.freeze(original);
Answer

const copy = {...original};

Spread copies only the top level, so nested objects remain shared. Direct assignment creates another reference to the same object, not a copy.

All Javascript MCQs

Login to manage your account

Please enter a valid email address.
Forgot Password?
Please enter a valid password.
OR

Don't have an account yet? Sign up as