Javascript p3 Flashcards

HTTP +

1
Q

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

A
    • an HTTP method, that describes the action to be performed.
    • the request target, usually a URL, or the absolute path of the protocol, port, and domain are usually characterized by the request context.
    • the HTTP version, which defines the structure of the remaining message, acting as an indicator of the expected version to use for the response.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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

A
    • the protocol version, usually HTTP/1.1
    • the status code, indicating success or failure of the request
    • the status text, a brief informational textual description of the status code to help a human understand the HTTP msg
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are HTTP headers?

A
    • similar to the head of an html doc, they hold specifics relevant to the data they head
    • they 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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

MDN Web Docs ! :D

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

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

A

– nope

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

What does the new operator do?

A
    • it calls a constructor function to make a new object with properties based on values given as arguments
    • it’s an instance of the object
- uses constructor function to make new instance of object, vs 
var newObj = obj.create(ogObj);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A
    • the Function.prototype property
  • -
    • x.prototype.prop = ‘value’;
    • object.getPrototypeOf(x).prop;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the instanceof operator do?

A

– it checks if the object is a product of the given constructor function

    • objX instanceof ObjectXMaker;
    • returns true

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

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
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(func, delay)

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

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

A
    • .setInterval(func, delay);

- - clearInterval(intervalID)

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

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

A

– 0, meaning execute immediately/next cycle

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

What do setTimeout() and setInterval() return?

A

a numeric, non-zero value which identifies the timer created by the call to setInterval()

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

What is AJAX?

A
    • AJAX is a technique in webdev which allows a page to request data from a server and load it without having to reload the entire page
    • selective reloading
    • uses JSON/HTML/XML
    • jQuery makes AJAX easier to use
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does the AJAX acronym stand for?

A

– the term Ajax is now used to
refer to a group of technologies that offer asynchronous functionality in the browser

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

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

A

– XMLHttpRequest

17
Q

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

A
    • load

- - progress, error, abort, timeout, etc

18
Q

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

A
    • prototypes

- - inherits from eventTarget

19
Q

explain:

var $userList = document.querySelector(‘#user-list’);
var xhr = new XMLHttpRequest();
xhr.open(‘GET’, ‘https://jsonplaceholder.typicode.com/users’);
xhr.responseType = ‘json’;
xhr.addEventListener(‘load’, function () {
console.log(xhr.status);
console.log(xhr.response);
for (let i = 0; i < xhr.response.length; i++) {
const newItem = document.createElement(‘li’);
newItem.textContent = xhr.response[i].name;
$userList.appendChild(newItem);
}
});
xhr.send()

A