Web dev 2 test 2

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which statement is FALSE about the async function below? async function someFunc(num) {// some code omittedreturn num * num; }

"someFUnc(2).then(alert);" is NOT a valid function call

Which statement if FALSE about promises?

A resolved Promise may be in a pending state

When using XML HttpRequest, when is the HTTP request sent?

After calling send()

Assume that using the undeclared message2 variable throws an exception. Choose ALL statements output by the code segment. function findError() {try {let message1 = "No errors";message2;console.log(message1);}catch (error) {console.log("Error");}finally {console.log("Finally");}}findError();console.log("Done");

Done, Finally

What is output to the console? function changeThings(someMovie) {someMovie.rating = "G";someMovie = { title: "Tron Legacy",rating: "PG-13"};}let movie = {title: "Tron",rating: "PG"};changeThings(movie);console.log(movie.rating);

G

What type of data can be expected from a third party RESTful web API?

JSON or XML

What does "Ajax is used with polling" mean?

Periodically the browser sends an HTTP request to the web server to see if data is available.

The fetch() method returns a _________.

Promise object

What does the following line of code do? localStorage.removeItem("name");

Removes the "name" key and associated value from storage

What is the purpose of the code below when creating unit tests? window.fetch = url => Promise.resolve({ ok: true, json: () => Promise.resolve(jsonResponse)});

Replaces fetch() temporarily so no HTTP requests are sent when testing

Why do third-party web API's often implement CORS?

To allow any website's page to send API requests

Which statement about unit testing is FALSE?

Unless XHR is mocked, Chai assert statements are likely to fail

How is a RESTful web service API called?

Using a URL and parameters

When would the function didNotWork() be called if the promise if fulfilled? promise.then(itWorked).catch(didNotWork);

When itWorked() throws an exception

________ is a JavaScript object used to communicate with a web server.

XML HttpRequest

Which line of code displays 2 to the power of 3 in a dialog box? function power(x, y) {return new Promise(function(resolve, reject) { let answer = 1;while (y > 0) {answer *= x;y--;}resolve(answer); });}

alert(await power(2, 3));

In the following JSON, the data type associated with friends is _____. {"friends": [ {"name":"Bobby"}, {"name":"Celia"}, {"name":"Judy"} ]}

array

What assert method is necessary to verify that arrays nums1 and nums2 contain the same elements?

assert.deepEqual(nums1, nums2);

What is missing to output the HTTP response body to the console? let url = "https://www.zybooks.com/";let response = await fetch(url);console.log(_____);

await response.text()

sessionStorage stores______ but localStorage stores_______

data that persists until the browser or tab is closed, data indefinitely

http://www.google.com and https://www.google.com are

different origins

The variable discountPrice has _____________. function musicTix(people, price) {if (people > 10) {var discountPrice = people * price * 0.9;return discountPrice;}return people * price;}

local scope

What line completes the code segment below so the output is "the secret"? _____console.log(localStorage.getItem("theKey"));

localStorage.setItem("theKey", "the secret");

How is the age field accessed after the following code is executed? let obj = JSON.parse('{"name":"Bobby", "age":20}');

obj.age

The Promise should be rejected if y is negative. What is missing from the if statement? function power(x, y) {return new Promise(function(resolve, reject) {if (y < 0) {_____} ... });}

reject(new Error("Message"));

The response variable is assigned with getch(), which returns a JSRON response. What method call returns an object that results from parsing the JSON response?

response.json()

What does stringify() return? JSON.stringify({"friends": [ {"name":"Bobby"}, {"name":"Celia"},{"name":"Judy"} ]});

single string

What does stringify() return? JSON.stringify({"friends": [{"name":"Bobby", "age":20}, {"name":"Celia", "age":30},{"name":"Judy", "age":21} ]}, ["friends", "age"]);

string with no names

The responseReceivedHandler() function is registered as the XMLHttpRequest's load event handler with response type "json". The JSON response looks like: {"title":"Rocky", "rating":"PG", "year":"1976"} What is missing from responseReceivedHandler() to display the movie title? function responseReceivedHandler() {let movieInfo = document.getElementById("movieinfo");if (this.status === 200) {movieInfo.innerHTML = "Title is <cite>" + ____.title + "</cite>";}else {movieInfo.innerHTML = "Movie data unavailable.";}}

this.response

Why is a key sometimes needed to access a third-party web API?

to obtain a key, a developer must agree to restricts on data received


Conjuntos de estudio relacionados

Ch 12 Endocrine Practice Quiz -E

View Set

Types of generalizability in qualitative research

View Set

Fundamental Information Security Chapter 11: Malicious Code and Activity

View Set