JavaScript Flashcards

Focused on Object Oriented Programming

1
Q

What is a method?

A

Function stored as a value in 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

Method definition is very similar to a function definition (no arguments being passed) while a method call would be the object.methodname(argument).

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

Describe method definition syntax (structure).

A

Function definition being assigned to a property of an object

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

Describe method call syntax (structure).

A

object.methodname(argument)

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

Method is associated as an object while functions are independent.

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

Object can contain both data and methods (behavior)

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

Inheritance, Polymorphism, Abstraction, Encapsulation

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

What is “abstraction”?

A

Taking complex problems and making it accessible. The best example is a light switch. There’s a lot that happens under the hood but to humans you just flick a switch.

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

Allows your products and services to communicate with other products and services without having to constantly build new connectivity infrastructure.

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

What is this in JavaScript?

A

Keyword referring to a variable that holds a value in an object you are working with

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

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
13
Q

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

A

Call time. It technically does not have a value until the function 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

Nothing it has not been invoked yet

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
Given the character object, what is the result of the following code snippet (character.greet())? Why?
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};
character.greet();
A

You will get the message because it retrieves the object with the property value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
Given the character object, what is the result of the following code snippet *var hello = character.greet; hello()? Why?
var character = {
  firstName: 'Mario',
  greet: function () {
    var message = 'It\'s-a-me, ' + this.firstName + '!';
    console.log(message);
  }
};
var hello = character.greet;
hello();
A

Undefined

17
Q

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

A

You can’t

18
Q

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

A

If there is a . it is always what is to the left of it

19
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototypal Inheritance

20
Q

What is a prototype in JavaScript?

A

Object that a bunch of objects can build off of

21
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

From prototypes

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

On the prototype

23
Q

What does the new operator do?

A
  1. Creates a blank, plain JavaScript Object
  2. Adds a property to the new object (__proto__) that links to the constructor functions prototype
  3. Binds newly created object instances as ‘this’ context
  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 prototype property of a constructor appears in the prototype chain. Returns a boolean