JavaScript Prototypes, Constructors, and Timers Flashcards

1
Q

What is a “callback” function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action

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

Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?

A

setTimeout();

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

How can you set up a function to be called repeatedly without using a loop?

A

By using setInterval(); function

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

What is the default time delay if you omit the delay parameter from the setTimeout() or setIntervale()?

A

0 seconds, it is instant

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

What do setTimeout() and setInterval() return?

A

setTimeout() { [native code] }

setInterval() { [native code] }

A number data type that is used for an ID in IntervalID so you can stop the function from running

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

What kind of inheritance does the JavaScript programming language use?

A

Object.setPrototypeOf(object, prototype);

Prototype

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

What is the prototype in JavaScript?

A

A prototype is an object that will be inherited into another object

Prototypes are the mechanism by which JavaScript objects inherit features from one another.

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

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

A

Strings, arrays, and numbers can borrow methods when they’re needed

JavaScript sets those prototypes on our behalf

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

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

A

It looks for it’s prototypal inheritance

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

What does a new operator do?

A

Allows you to create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

It creates a blank, plain JavaScript object

It adds a property to the new object (__proto__) that links to the constructor function’s prototype object

It binds the newly created object instance as the this context

Returns this if the function doesn’t return an object

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

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

A

Function.prototype property

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

What does the instanceof operator do?

A

instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object

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