javascript-constructors Flashcards

1
Q

What does the new operator do?

A

the new operator lets a dev create instances of an object
4 things:
1. creates a blank object
2. points the __proto__ property of the newlyCreatedInstance to the .prototype property of the constructor function
3. execute the constructor function w the given arguments binding newly created instance to this (i.e any reference to this in the constructor function now refers to the newlyCreatedInstance).
4 if the constructor returns an object this becomes the value of the entire new expression but if the return is a primitive, newlyCreatedInstance is returned instead

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

What property of JavaScript functions can store shared behavior for instances created with new?

A

.prototype property

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

What does the instanceof operator do?

A

checks if the object has a certain prototype

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