JS and Object-Oriented Programming Flashcards

1
Q

What is a method?

A

A function which is a property of an object.

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

How is a method different from any other function?

A

It is associated with an object

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

What is the defining characteristic of Object-Oriented Programming?

A

Related method and variables are bundled together in objects - a program is the interaction of the objects with each other

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

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

A
  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. polymorphism
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways.

also: hiding/abstracting away the details of how something is implemented to make working with it easier

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

What is the purpose of an API?

A

An API allows programs/objects to interact with other programs/objects and controls what can be accessed or modified.

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

What is the keyword ‘this’ in JavaScript?

A

A reference to the object that a method/function is related to/associated with;

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

It means that even if ‘this’ isn’t listed as a parameter in the function/method definition, it is still defined and available to use inside the function/method

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

Call-time;

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

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

A

You can’t. The value of this is determined at call time (it is a call-time binding)

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

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

A

Look at how/where the function/method is being called

– also check left of the dot

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

What kind of inheritance does the JavaScript programming language use?

A

Prototypal inheritance / prototype-based inheritance

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

What is a prototype in JavaScript?

A

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

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

The methods have been inherited through prototypal inheritance

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

17
Q

What does the ‘new’ operator do?

A

The keyword ‘new’ is used to initialize an instance of a constructor function.

What calling a function with ‘new’ keyword specifically does:

  1. Creates an empty javascript object
  2. Adds the __proto__ property to the object
  3. Sets ‘this’ keyword to reference the object created in step 1
  4. Returns ‘this’ object if the function doesn’t return an object.
18
Q

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

A

the prototype property

19
Q

What does the ‘instanceof’ operator do?

A

It is used to check if an object was made from another object (has the constructor somewhere in it’s prototype chain)