OOP Flashcards

1
Q

What is a method?

A

A function which is a property of an object that can either be instance or static methods.

*Instance methods are built-in tasks performed by an object instance. Static methods are tasks called directly on an object constructor.

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 uses the “function” keyword followed by a function code block that describes the method.

A method call uses the method name of its respective object followed by parenthesis and arguments (if any).

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

Describe method definition syntax (structure).

A

The property name and a colon followed by the function keyword, parameters (if any), and the function code block.

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 and method separated by the dot notation followed by parenthesis with 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 can be accessed through its object. Normal functions can be accessed anywhere.

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) and 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

Abstraction, Encapsulation, Inheritance, and Polymorphism.

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

What is “abstraction”?

A

The process of working with complex things in simple ways.

(i,e,. a light switch or automatic transmission.)

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

An API allows two or more computer programs to communicate with each other.

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

What is this in JavaScript?

A

This is a variable that its value is determined by when a function is called.

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

Implicit parameters can be understood from something else without being explained.

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

The value is determined by when the functioned is called.

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

This refers to nothing because the function is not called.

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

character.greet();

Given the above character object, what is the result of the following code snippet? Why?

A

The string, It’s-a-me-Mario! because the this keyword refers to what is left of the dot which is the character object that has the firstName property.

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

var hello = character.greet;
hello();

Given the above character object, what is the result of the following code snippet? Why?

A

The result is undefined because hello(); is equivalent to window.hello in which hello is not a property of window.

17
Q

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

A

You cannot tell what the value of this would be in function or method definitions.

18
Q

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

A

Whatever is to the left of the dot. If there is no dot, then it is window.

19
Q

What kind of inheritance does the JavaScript programming language use?

A

JavaScript uses prototype-based (or prototypal) inheritance. (JavaScript objects give certain behaviors (methods) or data (properties) to other objects.)

20
Q

What is a prototype in JavaScript?

A

An object that contains properties and methods that can be used by other objects.

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

The methods being called are defined on a separate prototype object.

22
Q

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

A

The prototype object that the object is set to.

23
Q

What does the new operator do?

A

When a function is called with the new keyword, the function will be used as a constructor. New will do the following:

  1. Creates a blank object.
  2. Points the prototype property of the created instance to the prototype property of the constructor.
  3. Runs the function (constructor) code block and makes the created instance (object) “this”.
  4. Returns an expression or the new object.
24
Q

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

A

The .prototype property.

25
Q

What does the instanceof operator do?

A

It tests to see whether the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is either true or false.