IST-239 Unit 3 Test

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Which of the following examples demonstrates the correct format for a simple cookie storing the value "blue" in the "color" data field?

"color=blue"

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

;path=/partyTime

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.

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

Suppose you have written JavaScript constructors for two object classes called ClassA and ClassB and then the statement ClassA.prototype = new ClassB();. ClassB can use the value returned by one of ClassA's methods in one of its own methods because ClassB inherits all the properties and methods of ClassA in this situation.

False

The following JavaScript statement will assign aDateobject storing the date July 4, 1776 and the time 6:00 p.m. to the variablehistoricDay. let historicDay = new Date("July 4, 1776 6:00:00");

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

Which statement regarding secure coding is accurate?

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

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

True

Attempting to use a variable that is referenced outside its lexical environment, which encompasses functions and the variables they use, will result in an error.

True

Given that a JSON data structure's text has been assigned as the value of the variabledictEntry, the following JavaScript statement will create an object with properties that can be accessed using dot or bracket notation. let dictEntryObj = JSON.parse(dictEntry);

True

Given that you can calculate the circumference of a circle by multiplying its diameter times pi, in JavaScript you can use the statement circumference = d * Math.PI; to calculate the circumference of a circle with the diameter d.

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

The following JavaScript code will successfully log the phrases "Character class: Wizard," "Character weapon: Staff of wisdom," and "Character healthLevel: 115" to the console. let character = { class: "Wizard", weapon: "Staff of wisdom", healthLevel: 115 }; for (let prop in character) { console.log("Character " + prop + ": " + character[prop]); }

True

The following JavaScript command adds a method to a built-in class that can be called on any object instance of that class. Array.prototype.scramble = function() { this.sort(function() { return 0.5 - Math.random(); }); }

True

The following JavaScript statements will store a date that is two years after the current date drawn from the computer's system clock in thetwoYrsFromNowvariable.

True

The regular expression/\b\$\d+/gwill match words beginning with a dollar sign and one or more digits, such as"$5"or"$500".

True

To extract the date and approximate time (in hours and minutes) from a JavaScriptDateobject, you can apply theget(Month),getDate(),getFullYear(),getHours(), andgetMinutes()methods to that object.

True

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

True

When you use the regular expression/(\w+)\s(\w+),?/gto match substrings, information about the substring matched by the first(\w+)group is stored in the$1property of the associated JavaScriptRegExpobject.

True

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

Suppose you have written code to create a JavaScript class calledbear. What command should you use to add a method calledhibernate to the template for thebear class (not to its constructor)?

bear.prototype.hibernate = function() { return "Zzzzzzz..."; }

What does the following JavaScript code do? let titles = "Mr.|Mrs.|Miss|Ms.|Dr."; let spotTitle = new RegExp(titles, "g");

defines a regular expression with a global flag by creating an object constructor

Suppose you want to define a constructor for objects of the customshoesclass. What should you place in the blank to complete the JavaScript command block for this purpose? _____ this.pairQty = shoePairQty; this.style = shoeStyle; this.sellPair() function() { this.pairQty =- 1; return this.pairQty; }; }

function shoes(shoePairQty, shoeStyle) {

Suppose you have just written a JavaScript constructor for a button class with the parameters buttonColor, buttonDiameterInches, and buttonHoles. Which statement can you use to create an instance of button to represent a blue, 0.25-inch button with four holes named button1?

let button1 = new button("blue", 0.25, 4);

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*365 document.cookie = "role=wizard;max-age=" + calcAge;

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

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

Given that that value of the each variable used is a text string, which of the following JavaScript statements achieves the same results aslet sentence = subject + predicate;?

let sentence = subject.concat(predicate);

Imagine that you've written a JavaScript constructor for a customclownfish object with aposition property and then added the following statements: clownfish.prototype.swimForward = function(distanceInCm) { this.position += distanceInCm; };

let spikey = new lionfish(); clownfish.prototype.swimForward.call(spikey, 50);

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);

Suppose you have just written a JavaScript constructor for abutton class and then created an instance of this class calledbutton1. Adding the following code to your program _____. function buttonCollection(ownerName) { this.buttonItems = []; this.owner = ownerName; } let myCollection = new buttonCollection("Mel"); myCollection.buttonItems.push(button1);

nests one custom object within another

What type of method isshowCategory() in the following JavaScript code? function stones(stoneCount) { this.count = stoneCount; function sizeCategory() { if (stoneCount > 10) return "Big"; else return "Small"; } this.showCategory = function() { console.log("Category: " sizeCategory()}; } }

privileged

What should you place in the blank to complete the following JavaScript statements if you want to store the Boolean true value in wordCheck if the string stored in text contains the word "phenomenon"? let regx = /phenomenon/; let wordCheck = _____;

regx.test(text)

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

Which method inherited by all objects in JavaScript can be used to return a text string representation of an object?

toString()

If, after the following JavaScript code executes, the value oftoppings is["cheese", "mushrooms", "peppers", "sauce"], what belongs in theblank? let toppings = ["sauce", "cheese", "mushrooms"]; toppings.pop(); _____ toppings.sort();

toppings.push("mushrooms", "peppers");

What will the value of the variable x be after the following JavaScript statements execute? let sampleRhyme = "Hickory, dickory, dock. The mouse ran up the clock."; let regx = /[^a-zA-Z]/; let x = sampleRhyme.search(regx);

7

In JavaScript, how are an object and an interface related to each other?

An interface allows another program to access an object's properties and methods.

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 thedocument.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 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.

After the following JavaScript statements are executed, the value ofsomeNumberswill be[5, 10, 30, 60, 200]. let someNumbers = [30, 5, 200, 60, 10]; someNumbers.sort();

False

After the following JavaScript statements execute, the value ofcrayonsis["pink", "blue", "green"]. let crayons = ["pink", "purple"]; crayons.shift(); crayons.unshift("blue", "green");

False

Every JavaScript object has a constructor function that acts as a template for all the properties and methods associated with the object's class, and a prototype, which can be thought of as a machine to instantiate objects.

False

To write a regular expression literal that matches the substring of characters"go", you place it between two backslashes, retaining the quotation marks, like this:\"go"\.

False

Using the statementdocument.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

When you need to store some properties of an object in a JSON text string so that you can supply data to another program in this format, you should use the JSON.parse()method and pass in the list of properties to include as part of the replacer argument.

False

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

False

Suppose you have written a JavaScriptfor loop, and one of the statements that will execute with each iteration of the loop includes an anonymous function that uses thefor loop's counter variable,i. Which statement about this loop is true?

The anonymous function will execute when it is called by the program, using the value of i at the time it was encountered in the loop.

Which statement about the JavaScriptpost andget 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.

If the value of y is 3.14, callingMath.floor(y) will return 3 and callingMath.ceil(y) will return 4.

True

In JavaScript, you can use theapply()method to borrow a method from one object class and use it on objects of a different class without defining the second class as an instance of the first class.

True

JavaScript Object Notation is a data interchange format that is not part of JavaScript but employs a similar syntax to organize data as a comma-separated list of key-value pairs.

True

After executing the following JavaScript code, the value of the variablepieFlavors will be _____. let pieFlavors = ["pecan", "apple", "lemon", "key lime"]; pieFlavors.reverse(); pieFlavors.sort();

["apple", "key lime", "lemon", "pecan"]

A JavaScript closure is created when _____.

a copy is made of a function that includes the lexical environment of variables used within that function

Custom objects _____.

are objects created by a programmer for specific tasks

The lexical scope of variables, functions, and other objects _____.

is based on their physical location within the source code

Suppose the web page you are working on contains one file input control with the id sourceText. What should you place in the blank within the following JavaScript code to assign an object with information about the first file chosen by the user to the variable text? document.getElementById("sourceText").onchange = function() { _____; };

let text = this.files[0]

Which JavaScript code should you use to create an object literal called toyCarColl with numberCars and cars properties?

let toyCarColl = { numberCars: 3, cars: ["Dumptruck", "Mustang", "Rabbit"] };

Suppose you have removed the punctuation marks from a text file consisting of several sentences and then stored the resulting string in the variable runOnSentences. Which JavaScript statement can you use at this point to store an array of substrings representing the individual words from runOnSentences in the variable wordList?

let wordList = runOnSentences.split(/\s+/g);

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 variablephoneField. Which statement can you use to convert the string value of this variable to"phone=(802) 555-4781"?

phoneField = decodeURIComponent(phoneField);

What type of method is theeat() method foriceCream object instances as defined in the following JavaScript statement? iceCream.prototype.eat = function() { return "Yum, yum!";

public

What does the following JavaScript code do? "Ring around the rosy!".indexOf("g");

returns 3

What JavaScript code belongs in the blank to create an object literal namedshoes? let shoes = new Object(); _____

shoes.pairQty = null; shoes.sellPair = function() { this.pairQty =- 1; return pairQty; };

Web storage _____.

stores data as an associative array within a file

Suppose you have stored a long string in thetext variable and would like to remove punctuation marks from it, then store the modified string in thetext2 variable. Which JavaScript statement should you use?

text2 = text.replace(/[^a-zA-Z\d\s]/g, "");

Suppose you plan to write code for an object literal in JavaScript that includes a method. You can call this method _____.

the same way you call a method for a built-in JavaScript object

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)


Ensembles d'études connexes

Implement Microsoft VPN Services Part Two

View Set

Essentials of Pediatric Nursing - Chapter 28

View Set

The Crucible act one questions and answers

View Set

AP Psychology Multiple Choice Questions

View Set

Unit 1: medical evacuation (MEDEVAC) Lesson:1 MEDEVAC BASICS

View Set

Security Data Analysis - CBT Nuggets

View Set

Cost Acct Midterm - Chapters 1-3

View Set