Are you ready?

1 questions to solve.

Instructions
  1. This quiz goes to full-screen once you press the Start button, or any Next button after exiting the quiz window.
  2. At the end of the quiz, you are able to review all the questions that you answered wrong and see their explanations.
What does the value 3 indicate for the readyState property?
readyState == 3 means that the content of the response body is in the process of being loaded. This goes with choice (A). See AJAX states for more info.
How many alerts are made by the code below, assuming that the request returns with a 200 OK status?
var xhr = new XMLHttpRequest();
xhr.open("GET", "foods.txt", true);

xhr.onreadystatechange = function() {
    if (this.status == 200) {
        alert("Success!");
    }
}

xhr.send();
The status property is filled with the value 200, starting at readyState equal to 2. Therefore this.status == 200 returns true for the states 2, 3 and 4; that sum up of three all together.
Which of the following shows the correct name for the function shown?
All the names shown below are invalid, except for the second one i.e XMLHttpRequest(). See Mechanism of AJAX for more info.
The following code doesn't run as expected. Determine the problem in it.
xhr.onreadystatechange = function() {
    if (this.readyState === 4 && this.status === "200") {
        alert(this.responseText);
    }
}
The problem is caused by the expression this.status === "200" (in line 2), as status doesn't return a string; but instead it returns a number. See AJAX States for more info.
What will the following code log?
var xhr = new XMLHttpRequest();
xhr.open("GET", "foods.txt", true);
xhr.send();

console.log(xhr.readyState);
The reason as to why choice (A) is the answer here, is detailed in the AJAX States chapter where we discuss how it works internally.
What does the third parameter of open() default to and what does this value mean?
var xhr = new XMLHttpRequest();
xhr.open("GET", "foods.txt", true);
xhr.send();

console.log(xhr.readyState);
open()'s third parameter defaults to true which indicates that the xhr request shall be sent asynchronously, behind the scenes. This goes with choice (C).