Objects, Prototypes and Classes Flashcards

1
Q

What is an Object literal?

A

A JavaScript object literal is a comma-separated list of name-value pairs wrapped in curly braces. Object literals encapsulate data, enclosing it in a tidy package. This minimizes the use of global variables which can cause problems when combining code.

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

How do equality operators work with objects?

A

equality operators compare memory addresses, not object values when using any of the equality operators so comparing two objects with == , ===, or Object.is() equality operators will equal false.

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

How do you copy or merge the properties of one object into another object?

A
  • Object.assign()
  • This takes multiple properties.
    • The first is the object that is going to take in new properties.
    • The second is the object being copied.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you avoid object mutation when using Object.assign()?

A

Object.assign take in an unlimited number of parameters. The first parameter will always be what gets added to. Therefore, you can make the first parameter in Object.assign() an empty object.

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

=== and Object.is() provide identical results except when?

A
  • Comparing NaN
  • Comparing negative 0 (-0)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why use bracket notation for objects?

A

If property names are not valid identifiers (i.e ‘hair color’)

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

What is the enumerable property on an object?

A
  • Enumerable is an object property that can be included in and visited during a for…in loop or a similar iteration of properties like Object.keys().
  • If this property is set to false then the object property can not be iterated over and would not appear in a list of Object.keys().
  • Setting enumerable to false also affects JSON serialization of an object.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can you prevent an objects property from being deleted from an object?

A

Set the objects configurable property to false. Important - if you change this property to false it is permanent. You cannot change it back to true.

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

How do you create getters and setters for Objects?

A

Object.defineProperty(objectName, ‘propertyName’{ get: function(){ return propertyName}, set: function(value) { //code to set property })

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

What is a prototype?

A

An object that exists on every function in JavaScript. There are two differnt protypes in JavaScript

  • A Functions’s prototype
  • An Object’s prototype
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Define Functions Prototype

A

The object instance that will become the prototype for ll objects created using this function as a constructor.

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

Define Objects Prototype

A

The object instance from which the object is inherited

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