Week 5 Quiz Questions Flashcards

1
Q

What is a method?

A

A method is 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 can you tell the difference between a method definition and a method call?

A

method call required an object to be associated with it. method definition is within an object, function keyword, etc.

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

Describe method definition syntax (structure).

A

var object = {methodName: function (param) {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

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

methods are directly related to the object they are associated with

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
Polymorphism

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

What is “abstraction”?

A

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

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

a way for 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 referring to calling object

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 the function code block even though it wasnt included in the function definition 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

on function call

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 the character object– character.firstName

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
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’ in .greet is directly referring to ‘character’

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

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

A

its a me undefined
‘this’ is now referring to the window object

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

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

A

look at the object left of the dot when the function is called

18
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based/ prototypal inheritance

19
Q

What is a prototype in JavaScript?

A

prototypes allow objects to inherit behaviors (methods) and data (properties) from objects
[[Prototype]]

20
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

using the Object.setPrototypeOf(object, prototype) method gives the selected object the functions/ methods of the prototype being entered.
via prototypal inheritance

21
Q

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

A

JS looks at its nearest prototype.

22
Q

What does the new operator do?

A

The new operator creates a new instance (instantiation) of an object that uses a constructor function as a blueprint

23
Q

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

A

prototypal inheritance

24
Q

What does the instanceof operator do?

A

tests to see if an object appears anywhere in a constructor. returns boolean

25
Q

What is a “callback” function?

A

a function that is in another function as an argument

26
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

using the setTimeout() global function

27
Q

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

A

using the setInterval() global function

28
Q

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

A

default is 0 milliseconds

29
Q

What do setTimeout() and setInterval() return?

A

returns a unique timeoutID number only associated with that particular instance. can use the same timeoutID in setTimeout() and setInterval() and clearInterval()

30
Q

What is a client?

A

requests services from a server

31
Q

What is a server?

A

provides resources/ services to client

32
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET

33
Q

What three things are on the start-line of an HTTP request message?

A

An HTTP method (a verb (like GET, PUT or POST) or a noun (like HEAD or OPTIONS)),
request target (usually a URL), and HTTP Version

34
Q

What three things are on the start-line of an HTTP response message?

A

protocol version, usually HTTP/1.1, A status code, (indicating success or failure of the request– usually 200, 404, 302), and status text (just information, doesnt change or add things, but more for human understanding)

35
Q

What are HTTP headers?

A

lets the client and the server pass additional information with HTTP request or response – ‘case insensitive name’: value

36
Q

Where would you go if you wanted to learn more about a specific HTTP Header?

A

mdn

37
Q

Is a body required for a valid HTTP request or response message?

A

no, can be blank

38
Q

What is AJAX?

A

a technique to load data into part of a page without having to reload the whole page.

39
Q

What does the AJAX acronym stand for?

A

asynchronous javascript and XML

40
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest()

41
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

‘load’ event

42
Q

Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

they both are capable of handling/supporting events