Object Oriented Programming (OOP) Flashcards

1
Q

What is a method?

A

a function stored in the 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 method definitions and method calls?

A

method definition will always have the function keyword and a code block.
method call is always attached to an object.

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

Describe method call syntax:

A

object.method( )

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

How is a method different from any other function?

A

a method is a property of an object

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

What is the defining characteristic of object-oriented-programming (OOP)?

A

objects can contain both data and behavior(methods)

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

What are the four principles of object-oriented-programming?

A

Abstraction, Encapsulation, Inheritance, Polymorphism

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

What is “abstraction”?

A

being able to work with complex things in simple ways

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
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
9
Q

What is the purpose of an API?

A

communication between two softwares

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

What is this in JavaScript?

A

an implicit parameter of all JavaScript functions - the object that we’re working in

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

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

A

it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var

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

When is the value of this determined in a function? Call time or definition time?

A

call time - this does not exist/have value until the function is called

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

How can you tell what the value of this will be for a particular function or method definition 👀?

A

you cant - if a function is just being defined, this does not exist yet

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

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

A

check the object to the left of the dot

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

What kind of inheritance does the JavaScript programming language use?

A

prototype-based inheritance (prototypal inheritance)

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

What is a prototype in JavaScript?

A

an object that contains properties and (predominantly) methods that can be used by other objects

17
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 prototype

18
Q

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

A

inside the prototype object linked to the object. it goes up the prototype chain until it finds what it needs

19
Q

What does the new operator do?

A
  • creates a blank, plain JavaScript object.
  • adds a property to the new object (__proto__) that links to the constructor function’s prototype object.
  • binds the newly created object instance as the this context (all references to this in the constructor function now refer to the object created in first step)
  • returns this
20
Q

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

A

the prototype property

21
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. The return value is a boolean value.
  • an instance is a created example of a thing
  • example :
function Car(make, model, year) {
  this.make = make;
  this.model = model;
  this.year = year;
}
const auto = new Car('Honda', 'Accord', 1998);
console.log(auto instanceof Car);
// expected output: true
22
Q

What is a ‘callback’ function?

A

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

23
Q

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

A

the setTimeout( ) global function

24
Q

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

A

setInterval( )

25
Q

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

A

0

26
Q

What do setTimeout( ) and setInterval( ) return?

A

a timeoutId