OOP (Object Oriented Programming) Flashcards

1
Q

What is a method?

A

A function stored in a property of an object

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

How can you tell the difference between a method definition and a method call?

A

o Method definitions will always have a function keyword and a code block
o Method calls start with an object name and has arguments that are being passed

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

Describe method definition syntax (structure).

A

propertyName: functionName( ) {
Return ‘anything’;
}

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

Describe method call syntax (structure).

A

objectName.method( )

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

How is a method different from any other function?

A

They are functions stored in an object

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

What is the defining characteristic of Object-Oriented Programming?

A

Objects can contain both:

   - Data (as properties)
   - Behavior (as methods)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the four “principles” of Object-Oriented Programming?

A

o Abstraction
o Encapsulation
o Inheritance
o Polymorphism

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

What is “abstraction”?

A

Being able to work with (possibly) complex things in simple ways (such as, turning a light on/off)

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

What does API stand for?

A

Application Programming Interface

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

What is the purpose of an API?

A

Give programmers a way to interact with a system(s) in a simplified, consistent fashion (aka abstraction) without knowing about how they all work independenly.

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

What is ‘this’ in JavaScript?

A

The object that you’re working within

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

What does it mean to say that this is an “implicit parameter”?

A

The parameter is available (in a function’s code block) even though it was never included in the function’s parameter list OR declared in a var

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

When is the value of ‘this’ determined in a function; call time or definition time?

A

Call time

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

What does ‘this’ refer to in the following code snippet?

var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};
A

Undefined (there is nothing in front of greet)

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

Given this character object:

var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};

What is the result of the following code snippet? Why?
character.greet();

A

It’s a me, Mario! Because greet is being called on the character object

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

Given this character object:

var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};

What is the result of the following code snippet? Why?
var hello = character.greet;
hello();

A

It’s a me, undefined!

Because ‘this’ is being called from the window object and not the character object

17
Q

How can you tell what the value of ‘this’ will be for a particular function or method DEFINITION?

A

There is no way to know in a definition because there is no value yet

18
Q

How can you tell what the value of this is for a particular function or method CALL?

A

By checking the object left of the dot

19
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based (prototypal) inheritance

20
Q

What is a prototype in JavaScript?

A

Object with properties and methods that can be reused

21
Q

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

A

Via inheritance from the prototypes (prototypal inheritance)

22
Q

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

A

its prototype (starts from the nearest prototype and moves up until it finds what it needs)

23
Q

What does the ‘new’ operator do?

A

Let you create an instance of a user-defined or built-in object type that has a constructor function (create a function that generates objects for you).

  1. Creates a blank, plain JavaScript object.
  2. Adds a property to the new object (__proto__) that links to the constructor function’s prototype object
  3. Binds the newly created object instance as the this context (i.e. all references to this in the constructor function now refer to the object created in the first step).
  4. Returns this if the function doesn’t return an object.
24
Q

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

A

prototype property

25
Q

What does the instanceof operator do?

A

Tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object and returns a Boolean value

26
Q

What is a “callback” function?

A

A function passed into another function as an argument

27
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()

28
Q

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

A

setInterval()

29
Q

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

A

0 (it will execute as soon as all the other codes finish running)

30
Q

What do setTimeout() and setInterval() return?

A
timeoutID
(you always want to set your var countdownId = setInterval( variable, time) so when you declare your clearInterval(), you can pass your countdownId so it stops the process when you need it to instead of running forever)