JS Prototypes & JS Constructors Flashcards

1
Q

What kind of inheritance does the JavaScript programming language use?

A

JS uses prototype-based inheritance

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

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on objects, arrays, and numbers?

A

Due to JS prototypes; models that was created that contain these methods.

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

If an object does not have its own property or method by a given key, where does JavaScript look for it?

A

From the object’s prototype, if it’s not there then object’s object’s prototype

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

What does the <b>new</b> operator do?

A

<ul>The new keyword does the following things:
<li>Creates a blank, plain JavaScript object</li>
<li>Links (sets the constructor of) the newly created object to another object by setting the other object as its parent prototype;</li>
<li>Passes the newly created object from Step 1 as the this context;</li>
<li>Returns this if the function doesn't return an object.</li>
</ul>

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

What property of JavaScript functions can store shared behavior for instances created with <b>new</b>?

A

Prototype property

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

What does the <b>instanceof</b> operator do?

A

It tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. Returns a boolean.

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