Instructions

  • 1. Your final score will reflect your grasp of the concepts—approach each question with precision.
  • 2. Thoroughly review each solution before proceeding to ensure full understanding.
  • 3. Final results will be available after submission to provide insights into areas for further improvement.
  • 4. Maintain academic integrity—plagiarism undermines learning and professional growth.
  • 5. Once submitted, responses are final, so ensure you’re confident in your answers.
  • 6. These challenges are designed to test practical knowledge; apply your skills as you would in real-world scenarios.

All Problems

Question

Action

How do you create a shallow copy of an object?

View

What is the difference between shallow and deep cloning?

View

What is the result of the following code?

View

What does the Object.assign() method do?

View

How do you merge two objects together using the spread operator?

View

Which method would you use for deep cloning an object?

View

What happens if two objects have the same property when merging?

View

What is the result of the following code?

View

How do you prevent modifications to an object after it has been created?

View

What is the difference between Object.freeze() and Object.seal()?

View

How do you create a shallow copy of an object?

Object.clone(obj)
Object.assign({}, obj)
Object.copy(obj)
Object.duplicate(obj)

What is the difference between shallow and deep cloning?

Shallow cloning only copies references to nested objects, while deep cloning copies all objects and nested objects.
Shallow cloning copies all objects, while deep cloning does not.
Shallow cloning copies primitive values, while deep cloning copies objects.
Shallow cloning does not exist.

What is the result of the following code?

const obj1 = { a: 1 }; const obj2 = { b: 2 }; const merged = { ...obj1, ...obj2 }; console.log(merged);

{ a: 1, b: 2 }
{ a: 1 }
{ b: 2 }
{ a: [1, 2] }

What does the Object.assign() method do?

Copies properties from one or more source objects to a target object.
Modifies the target object’s prototype.
Deletes properties from the target object.
Freezes the target object.

How do you merge two objects together using the spread operator?

{ ...obj1, ...obj2 }
Object.merge(obj1, obj2)
[obj1, obj2]
Object.clone(obj1, obj2)

Which method would you use for deep cloning an object?

JSON.parse(JSON.stringify(obj))
Object.assign({}, obj)
Object.clone(obj)
Object.create(obj)

What happens if two objects have the same property when merging?

The last object’s property overwrites the earlier one.
The first object’s property is kept.
Both values are merged into an array.
An error is thrown.

What is the result of the following code?

const obj1 = { a: 1, b: 2 }; const obj2 = { b: 3, c: 4 }; const merged = Object.assign({}, obj1, obj2); console.log(merged);

{ a: 1, b: 3, c: 4 }
{ a: 1, b: 2, c: 4 }
{ a: 1, c: 4 }
{ a: 1, b: [2, 3], c: 4 }

How do you prevent modifications to an object after it has been created?

Object.freeze()
Object.preventExtensions()
Object.seal()
Both a and c

What is the difference between Object.freeze() and Object.seal()?

Object.freeze() makes an object completely immutable, while Object.seal() allows modifications to existing properties.
Object.seal() makes an object completely immutable, while Object.freeze() allows modifications to existing properties
Both do the same thing.
Object.freeze() allows adding new properties, while Object.seal() does not.