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
What is a "callback" function?
a function that is in another function as an argument
26
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?
using the setTimeout() global function
27
How can you set up a function to be called repeatedly without using a loop?
using the setInterval() global function
28
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
default is 0 milliseconds
29
What do setTimeout() and setInterval() return?
returns a unique timeoutID number only associated with that particular instance. can use the same timeoutID in setTimeout() and setInterval() and clearInterval()
30
What is a client?
requests services from a server
31
What is a server?
provides resources/ services to client
32
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
33
What three things are on the start-line of an HTTP request message?
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
What three things are on the start-line of an HTTP response message?
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
What are HTTP headers?
lets the client and the server pass additional information with HTTP request or response -- 'case insensitive name': value
36
Where would you go if you wanted to learn more about a specific HTTP Header?
mdn
37
Is a body required for a valid HTTP request or response message?
no, can be blank
38
What is AJAX?
a technique to load data into part of a page without having to reload the whole page.
39
What does the AJAX acronym stand for?
asynchronous javascript and XML
40
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest()
41
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
'load' event
42
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
they both are capable of handling/supporting events