OOP Flashcards

1
Q

What is a method?

A

JavaScript methods are actions that can be performed on objects.

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

a method definition is what it will do or can do and how

a method call is it actually doing what its supposed to

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

Describe method definition syntax (structure).

A

name then colon followed by function and params the opening code block braces then code then closing code block braces

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

Describe method call syntax (structure).

A

the object name followed by the method and parenthesis and arguments if any

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

methods are defined in an object while functions are not

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

A feature of objects is that an object’s own procedures can access and often modify the data fields of itself (objects have a notion of this or self)
/can contain both data and methods(functionality)

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

What is this in JavaScript?

A

implicit parameter of all JS functions / gives you the lexical scope of whatever it is in

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

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

A

that 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
10
Q

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

A

the value of this is determined when the function is called

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

character

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

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

‘It’s a me Mario! / this refers to character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

‘It’s a me undefined! / this is referring to the window

as hello is whats calling it

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 will be for a particular function or method definition?

A

depends on how its called. If its attached to an object then its the object. If not you cant really tell

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

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

A

Depends if it is attached to an object

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

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (or prototypal) inheritance.

17
Q

What is a prototype in JavaScript?

A

a JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects.

18
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

they are inherited

19
Q

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

A

in its prototype / looks in its prototype chain

20
Q

What does the new operator do?

A

creates a new instance of a user defined object

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.

21
Q

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

A

prototype

22
Q

What does the instanceof operator do?

A

checks if one in item is an instance of another /
The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object.

23
Q

What is a “callback” function?

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.

24
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

25
Q

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

A

SetInterval

26
Q

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

A

0

27
Q

What do setTimeout() and setInterval() return?

A

A timeOutID / intervalId