CIT 171 Chapter 9 Review

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

Suppose you want the cookie defined by the following JavaScript statement to be accessible to the web pages that reside in the partyTime folder and all its subfolders on the web server. What should you place in the blank?document.cookie = "cakeFlavor=carrot_____";

;path=/partyTime

Suppose you have used the following JavaScript code to define cookies for a web page:document.cookie = "userName=Robertson;path=/partyTime;secure";document.cookie = "cakeFlavor=carrot;path=/partyTime;secure";document.cookie = "theme=Pirates;path=/partyTime;secure";When you want to retrieve the field names and values stored in the document.cookie object using JavaScript, what should you do first?

Call the method document.cookie.split("; "), creating an array of name=value pairs for each stored cookie.

How can you erase data that your JavaScript commands have stored in local storage?

Call the removeItem() method on the localStorage object, passing in the key for the data item you want to remove.

Which statement comparing web cookies and web storage as data storage options is accurate?

Cookies require access to a web server for testing and development, whereas web storage does not.

How do session storage objects compare with local storage objects?

Data stored in a local storage object can be accessed at any time, whereas session data is accessible only during the current session.

What is the difference between session cookies and persistent cookies?

Persistent cookies are available beyond the current browser session.

Which statement regarding secure coding is accurate?

The first line of defense in securing a JavaScript program is to validate all user input.

Which statement about the JavaScript post and get methods is true?

The post method appends form data to the body of the HTTP request.

Which statement accurately characterizes a stateless design for web sessions?

This type of design can be quite efficient but also limiting because it does not allow information and actions from one session to be preserved for future sessions.

Web storage ensures data integrity by adhering to the same-origin policy, which _____.

bars a website from accessing data stored by a web page with a different protocol, port, or host

Query strings _____.

begin with the ? character and contain data stored as field=value pairs

It is considered best practice to confine cookies to those folders and subfolders on the web server where they are needed because this ensures that all cookies within a website must have unique names.

false

Regardless of the browser used to access a web page, a cookie created with the statement:document.cookie = "theme=Pirates;path=/partyTime;secure";can be deleted with the statement:document.cookie = "theme=;max-age=0";

false

The same-origin policy prohibits the use of third-party scripts that run from a different web server than the current web page's server, even when those scripts are referenced by the current page's HTML file.

false

Using the statement document.cookie = "cakeFlavor=carrot;domain=weather.com"; to define a cookie makes it available to all domains on the weather.com website, whether or not they are found on your web server.

false

You can read a cookie's field values using built-in JavaScript methods such as readCookie().

false

If the current date is March 1, 2023, which JavaScript statement(s) should you use to set an expiration date for a cookie that is one year in the future?

let calcAge = 60*60*24*365document.cookie = "role=wizard;max-age=" + calcAge;

Suppose you have stored a query string that has already been processed to replace any + or URI-encoded characters in the variable queryString. What belongs in the blank in the following JavaScript code if you want to print the names and values of the form fields to the log?let formInfo = queryString.split(/&/g);for (let items of formInfo) {_____let fieldName = fieldValuePair[0];let fieldValue = fieldValuePair[1];console.log("Name: " + fieldName + ", value: " + fieldValue);}

let fieldValuePair = items.split(/=/);

Which JavaScript statement can you use to retrieve a query string from the current web page's URL and assign it to the queryString variable?

let queryString = location.search.slice(1);

Suppose you need to save a string that contains spaces and punctuation marks to a cookie as a data value. If you have assigned the string to the variable tagLine, what statement should you include in your code before the one creating the cookie?

let tagLine2 = encodeURIComponent(tagLine);

If you want to store the string "Cherry cola" in the variable mySoda, what should you place in the blank in the following JavaScript statements?localStorage.setItem("Flavor", "Cherry cola");mySoda = _____;

localStorage.getItem("Flavor")

Which JavaScript statement should you use to permanently store "MagicCity1" as the value for a user's log-in name so that the browser can access it in the future?

localStorage.setItem("login", "MagicCity1");

You have retrieved the query string "phone=%28802%29%20555-4781" and saved it in the variable phoneField. Which statement can you use to convert the string value of this variable to "phone=(802) 555-4781"?

phoneField = decodeURIComponent(phoneField);

Sam writes and executes a program that can open a web page containing a form and enter JavaScript code in a form field. In this manner, Sam's program successfully retrieves sensitive information from the web server. Sam's actions, which changed the web page's functioning, _____.

represent a code injection attack

Web storage _____.

stores data as an associative array within a file

A common strategy among JavaScript developers whose web apps employ cookies is to write a function that assembles the text string for a cookie from a list of values that is passed in, then stores that text string as a document cookie.

true

Adding the secure attribute to a cookie specifies that the cookie must be exchanged over an HTTPS connection rather than an HTTP connection.

true

Large organizations commonly utilize content delivery networks, which generally provide content from their own domain rather than the client's domain, to serve their websites.

true

Web browsers provide tools you can use to view and manage web storage objects, which the browser organizes by origin.

true

Which JavaScript statement should you place in the blank if you want to create an event handler that opens a dialog box to alert the user to a change in the data saved to web storage?_____ {window.alert("Value of " + e.key + " changed from "+ e.oldValue + " to " + e.newValue + ".");}

window.onstorage = function(e)


Conjuntos de estudio relacionados

U.S. History Chapters 25, 26, 27, & 28 Terms and Review Questions

View Set

Modern Principles of Economics (1)

View Set

Chapter 13: The Federal Reserve System

View Set

Chapter 16: Managing Organization Culture

View Set