Week 5 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 definition is the function inside an object which has a name followed by a colon, while method call is when you call its method with arguments or without arguments

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

Describe method definition syntax (structure).

A

First you declare the object by creating a variable and equaling it to curly braces. Within the curly braces you have properties which can be given any name and then a colon. Following the colon you have a function. If you want to add more properties you have to add a comma at the end of the closing curly brace. If not, close the object with a closing curly brace followed by a semicolon.

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

Describe method call syntax (structure).

A

You call the object name followed by a period, then the name of the property followed by parentheses with arguments if it has 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

A method is associated with a object and functions are not.

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

The purpose of API is to communicate between apps with each other as intermediary, where both apps might have been built with different tools and technologies.

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

What is this in JavaScript?

A

It is an implicit parameter of all JavaScript functions. The value of this is determined by how 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

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

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

window until we call it then it will be the character object

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! Because our character object is responsible in calling the greet function.

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

It’s-a-me, undefined! The hello function is not being called as a method of an object so it defaults to the window object, which does not have this.firstName so it is undefined.

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 will be for a particular function or method definition?

A

You can until the function is called.

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

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

A

Looks to the object to the left of the dot or it defaults to the global window object.

19
Q

What kind of inheritance does the JavaScript programming language use?

A

Prototype-based inheritance or prototypal

20
Q

What is a prototype in JavaScript?

A

Prototypes are the mechanism by which JavaScript objects inherit features from one another.

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

Those methods are defined on a “prototype” object and simply borrow those methods when they are needed.

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

Looks in the object’s prototype chain

23
Q

What does the new operator do?

A

The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

It can create a new object with the formats of an object that has a constructor function.

24
Q

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

A

Prototype

25
Q

What does the instanceof operator do?

A

It tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object and returns a boolean value.

26
Q

What is a “callback” function?

A

A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

27
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

setTimeout() method

28
Q

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

A

setInterval() method

29
Q

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

A

0

30
Q

What do setTimeout() and setInterval() return?

A

They both return a numeric ID value that identifies the timer created and can be used to cancel the timer.

31
Q

What is a client?

A

The clients are the ones who request a service. They are either a laptop, computer, or smartphone

32
Q

What is a server?

A

A computer that provides the network resources and provides service to other computers when they request it

33
Q

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

A

GET method

34
Q

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

A

http, an http method (get, put, post), the absolute URL

35
Q

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

A

The protocol version (HTTP/1.1), a status code either 200, 404, 302, and a status text

36
Q

What are HTTP headers?

A

HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon (:), then by its value

37
Q

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

A

MDN

38
Q

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

A

NO, it is a optional but it is commonly used.

39
Q

What is AJAX?

A

AJAX allows you to collect data to update parts of the DOM of an HTML page without the need for a full page refresh.

40
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

41
Q

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

A

XMLHttpRequest

42
Q

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

A

load event

43
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

Prototypal inheritance