JS 2025 Flashcards

1
Q

What’s the best way to clone an Object?

A

structuredClone(objectName)

alternative: JSON.parse(JSON.stringify(objectName) and assign to a new object (=)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you protect an Object from any modifications? No changes to values, no new/deleted properties?

A

Object.freeze(objectName)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you protect an Object from new/deleted properties

A

Object.seal(objectName)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you protect an Object from new properties only?

A

Object.preventExtensions(objectName)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you compare the Objects properly?

A
  1. JSON.stringify(object1) === JSON.stringify(object2)
  2. _.isEqual(obj1, obj2)

Objects need to be converted to strings to be compared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Iterating through an object dynamically

People often loop using for…in, but a better way is to get all Keys

A

console.log(Object.keys(product));
// ✅ [“name”, “specs”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Iterating through an object dynamically

People often loop using for…in, but a better way is to get all Values

A

console.log(Object.values(product));
// ✅ [“Laptop”, { ram: “16GB”, storage: “512GB” }]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Iterating through an object dynamically

People often loop using for…in, but a better way is to get all Keys & Values

A

console.log(Object.entries(product));
// ✅ [[“name”, “Laptop”], [“specs”, { ram: “16GB”, storage: “512GB” }]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly