last
What will futureValue contain after the for loop has been executed one time? var years = 10; var annualRate = 10; var futureValue = 1000; annualRate = annualRate / 100; for ( i = 1; i <= years; i++ ) { futureValue += futureValue * annualRate; } a. 1010 b. 11000 c. 1100 d. 1000
1100
Which of the following statements about associative arrays is true? a. you don't delete elements from an associative array b. an associative array does not have a length property. c. an associative array uses strings as the indexed. d. the for-in loop won't work with an associative array.
An associative array uses strings as the indexes.
Which type of object is passed to a function by value? a. Array b. Object c. Boolean d. Date
Boolean
Given the following lines of code, what will be displayed in successive dialog boxes? var answers = [ "C", "B", "D", "A" ]; delete answers[3]; for ( var i = 0; i < answers.length; i++ ) { alert(answers[i]); } a. C,B,D b. C,B,A c. C d. C,B,D,undefined
C,B,D,undefined
What happens when an exception is thrown inside a try block? a. the function returns a value of undefined b. an error message is displayed in the browser's console window c. the exception is rethrown to the calling function d. Control is transferred to the first statement in the catch block
Control is transferred to the first statement in the catch block
What is displayed when the following code executes? var statusCode = "403"; switch ( statusCode ) { case "200": alert("OK"); break; case "403": alert("Forbidden"); break; case "404": alert("Not Found"); break; default: alert("Unknown Status"); break; } a. unknown status b. not found c. OK d. Forbidden
Forbidden
All parameters passed to a function are available in what property of the function? a. settings b. arguments c. options d. parameters
arguments
Now that HTML5 is used by all modern browsers, the HTML div element should be used primarily for grouping a. lists and links b. elements for JavaScript and jQuery applications c. images and text d. elements for headers and footers
elements for JavaScript and jQuery applications
Which method removes the last element from the end of an array? a. push b. pop c. shift d. unshift
pop
A jQuery selector includes all but one of the following. Which one is it? a. dot operator b. quotation marks c. $ sign d. parentheses
quotation marks
Which of the following statements performs a case-insensitive comparison of the strings named text1 and text2? a. text1.toLowerCase() == text2.toLowerCase() b. text1 = text2 c. text1.toLowerCase() = text2.toLowerCase() d. text1 == text2
text1.toLowerCase() == text2.toLowerCase()
What method of the Math object can be used to return the largest value from the values that are passed to it? a. the Math.ceil method b. the Math.abs method c. the Math.max method d. the Math.pow method
the Math.max method
var invoice = { getSalesTax: function( subtotal ) { return ( subtotal * this.taxRate ); }, getTotal: function ( subtotal, salesTax ) { return subtotal + salesTax; }, taxRate: 0.0875 }; (Refer to code example 11-1.) This code creates an object with a. 3 properties b. 3 methods c. 2 methods and 1 property d. 1 method and 2 properties
2 methods and 1 property
var testScores = []; testScores[0] = [80, 82, 90, 87, 85]; testScores[1] = [79, 80, 74, 82, 81]; testScores[2] = [93, 95, 89, 100, 85]; testScores[3] = [60, 72, 65, 71, 79]; (Refer to code example 9-1) This code creates a tabular structure that has a. 4 rows and 4 columns b. 4 rows and 5 columns c. 5 rows and 4 columns d. 5 rows and 5 columns
4 rows and 5 columns
What does the following code do? Number.prototype.toCurrencyString = function () { return "$" + this.toFixed(2); } a. adds a cascading property to the Number object b. Returns a Number object c. Creates a method that can be called from a variable that holds an integer or floating-point number d. Adds a cascading method to the Number object.
Creates a method that can be called from a variable that holds an integer or floating-point number
var Employee = function(firstName, lastName) { this.firstName = firstName; this.lastName = lastName; }; Employee.prototype.getFullName = function() { return this.firstName + " " + this.lastName; }; (Refer to code example 11-3.) The following code displays var employee = new Employee("Grace", "Hopper"); alert (employee.firstName); a. Hopper b. Grace Hopper c. Grace d. Hopper Grace
Grace
If a numerical operation returns a number greater than the largest possible JavaScript value, it returns a. Infinity b. -NaN c. NaN d. -Infinity
Infinity
What does the second statement that follows do? var numbers = [1, 2, 3, 4]; numbers.length = 0; a. Nothing b. Only changes the value of the length property c. Removes all the elements in the array d. Sets all the elements in the array to undefined.
Removes all the elements in the array
What JSON string does the following code produce? var tasks = []; tasks.push("Go to the store"); tasks.push("Do laundry"); var json = JSON.stringify(tasks); alert ( json ); a. "Go to the store", "Do laundry" b. [{"task":"Go to the store"},{"task":"Do laundry"}] c. ["Go to the store","Do laundry"] d. {"task":"Go to the store, Do laundry"}
["Go to the store","Do laundry"]
Which of the following is used in a regular expression pattern to match the beginning of a string? a. $ b. ^ c. * d. ?
^
If you're using the Chrome browser and a JavaScript application stops running due to an error in the JavaScript code, you can identify the statement that caused the error by a. Pressing F12, and reviewing the code in the Sources panel b.pressing F12, clicking on the link in the Sources panel, and reviewing the code in the Console panel c.pressing F12 and reviewing the code in Console panel d.pressing F12, clicking on the link in the Console panel, and reviewing the code in the Sources panel
a. Pressing F12, and reviewing the code in the Sources panel
To provide for implicit iteration, a plugin should use a. the this keyword b. an each method c. a while loop d. a for loop
an each method
For the following code, an event handler named investment_change is var investment_change = function() { var years = parseInt( $("years").value ); alert("Years: " + years); } window.onload = function() { $("investment").onchange = investment_change; } a. attached to the onload event of a control with an id of "investment". b. attached to the onchange event of the global window object. c. attached to the onchange event of a control with an id of "investment". d. attached to the onload event of the global window object.
attached to the onchange event of a control with an id of "investment".
Which of the following statements gets the same result as this statement? localStorage.name = "Grace"; a. localStorage.claer() b. localStorage.removeItem("name") c. localStorage.setItem("name","Grace") d. localStorage.getItem("name)
c. localStorage.setItem("name","Grace")
var employee = { name: "G. Hopper", start: new Date("1/1/2000"), salary: 90000 }; var regions = ["northwest", "southwest", "central", "east"]; var replacer = function (key, value) { if (key === "") { return value; } if (key === "salary") { return undefined; } if (typeof value === "string") { var first = value.substring(0,1).toUpperCase(); var remaining = value.substring(1); return first + remaining; } else { return value; } }; (Refer to code example 16-2) What JSON string does the following code produce? JSON.stringify(employee, replacer); a. {"name":"g. hopper","start":"1/1/2000","salary":9000} b. {"name":"G. Hopper","start":"2000-01-01T08:00:00.000Z","salary":9000} c. {"name":"G. Hopper","start":"2000-01-01T08:00:00.000Z"} d. {"name":"G. Hopper","start":"1/1/2000"}
c. {"name":"G. Hopper","start":"2000-01-01T08:00:00.000Z"}
Cross-browser compatibility is a serious development issue because Internet Explorer and the other browsers don't always interpret a. HTML the same way b. HTML and CSS the same way c. CSS the same way d. HTML, CSS, and JavaScript the same way
d. HTML, CSS, and JavaScript the same way
Which operator returns true if an object is the specified object type? a. instanceof b. is c. typeof d. in
instanceof
Which method returns the elements of an array in a string separated by a comma? a. join b. concat c. splice d. shift
join
When you test an application with Chrome's developer tools and a breakpoint is reached, you can view the current data by a. hovering the mouse pointer over a variable name in the Elements panel b. clicking in the bar to the left of a statement that uses an arithmetic expression c. looking up the variable in the names table in the Console panel d. moving the mouse pointer over the name of a variable in the Sources panel
moving the mouse pointer over the name of a variable in the sources panel
Which method accepts a function that combines all the elements in the array and then returns the resulting value? a. reduce b. filter c. map d. concat
reduce
How can you clear a check from a Checkbox object? a. set its checked property to false b. set its value property to an empty string c. call its blur method d. set its clear property to true
set its checked property to false
What does the code that follows do? $("email").firstChild.nodeValue = "Entry is invalid."; a. sets the text for the first child of the element with "email" as its id attribute. b. sets the text for the element with "email" as its id attribute. c. sets the text for the next child of the element with "email" as its id attribute. d. gets the text for the element with "email" as its id attribute.
sets the text for the first child of the element with "email" as its id attribute.
After the statement that follows is executed, rateText represents var rateText = document.getElementById("rate"); a. the HTML element with "rate" as its id attribute b. the value that was entered in the HTML element with "rate" as its id attribute c. the string that was entered in the HTML elements with "rate" as its id attribute
the HTML element with "rate" as its id attribute
What event occurs when the user selects a new item from a select list? a. the dbclick event b. the click event c. the select event d. the change event
the change event
$("#faqs h2").click(function(evt) { $(this).toggleClass("minus"); if ($(this).attr("class") != "minus") { $(this).next().hide(); } else { $(this).next().show(); } evt.preventDefault(); }); (Refer to code example 17-1) What does the this keyword refer to in this code? a. the current h2 heading in the processing loop b. the click event method c. the anonymous function for the click event method d. the h2 heading that was clicked
the h2 heading that was clicked
For a Textarea object, what property do you use to get the text that has been centered into the text area? a. the name property b. the string property c. the text property d. the value property
the value property
An HTTP response is sent from a. the client to the web server b. the application server to the web server c. the web server to the client d. the web server to the application server
the web server to the client
Which parameters are required when you call the Date constructor with number parameters? a. the year, month, day, and hours b. the year, month, day, hours, and minutes c. the year, month, and day d. the year and month
the year and month
Which of the following jQuery methods can you use to get the value of a text box? a. text(value) b. val() c. val(value) d. text()
val()
Which of the following is a valid statement for declaring and initializing a variable named length to a starting value of 120? a. var length = 120 b. num length = 120 c length = 120 d int length = 120
var length = 120
Assume that you have an object of the Object type named employee. Assume also that this object only has two properties named firstName and lastName. What does the following code do? employee.streetAddress = "123 Main Street"; a. It causes an error because no property named streetAddress exists for the employee object. b. It adds an event named streetAddress to the employee object. c. It adds a property named streetAddress to the employee object. d. It adds a method named streetAddress to the employee object.
It adds a property named streetAddress to the employee object.
What is the value of the message variable after the following code executes? var message = ""; for (var i = 0; i < 5; i++ ) { message += "L:" + i + ","; } a. L:5 b. L:1, L:2, L:3, L:4, L:5 c. L:0, L;1, L:2, L:3, L:4 d. L:0, L;1, L:2, L:3, L:4, L:5
L:0, L;1, L:2, L:3, L:4
What is displayed when the following code executes? var age = 19, score = 750; if ( age >= 21 && score >= 700 ) { alert ("Loan approved"); } else if ( age >= 21 && score >= 650 ) { alert ("Cosigner needed."); } else if ( age >= 18 && score >= 680 ) { alert ("Two cosigners needed."); } else { alert ("Loan denied."); } a. Cosigner needed. b. Load denied. c. Load approved. d. Two cosigners needed.
Two cosigners needed
Within a CSS rule set, a rule includes a. a selector and a declaration block b. a selector and a value c. a property and a selector d. a property and a value
a property and a value
Sometimes, validating the HTML code for a web page will help you debug an application, because a. validation will catch some JavaScript errors. b. a trivial HTML error can cause other types of errors. c. the page won't run in a browser if it isn't valid. d. you can be sure that a validated page will work correctly in a browser.
a trivial HTML error can cause other types of errors.
What is the value of salesTax after the following code executes? var salesTax = 53.937; salesTax = parseFloat( salesTax.toFixed(2) ); a. 53.94 b. 53.937 c. NaN d. 53.93
a. 53.94
When a JavaScript object is serialized, a. only the object's data is serialized, not its methods b. its original structure is lost c. it can only be deserialized if you use one of the textual data formats d. it can be transmitted but not stored
a. only the object's data is serialized, not its methods
var add = function( x, y ) { return ( x + y ); } alert( add (5, 3) ); (Refer to code example 10-1.) The function a. accepts 2 parameters and returns 1 value b. accepts 2 parameters and returns 2 values c. does not accept a parameter and returns 1 value d. accepts 2 parameters and does not return a value
accepts 2 parameters and returns 1 value
var add = function( x, y ) { return ( x + y ); } alert( add (5, 3) ); (Refer to code example 4-1) The function in this example a. accepts 2 parameters and returns 1 value. b. accepts 2 parameters and returns 2 values. c. does not accept a parameter and return 1 value. d. accepts 2 parameters and does not return a value.
accepts 2 parameters and returns 1 value
var json = "[{\"task\":\"Do taxes\",\"due\":\"2016-04-15T07:00:00.000Z\"}"; json = json + ",{\"task\":\"Do Laundry\"}]"; var tasks = JSON.parse(json); (Refer to code example 16-1) What JavaScript does this code produce? a. An array with three elements, each of which is null. b. an object with three properties. c. an array with two elements, each of which is an object d. this code throws an exception
an array with two elements, each of which is an object
When a client requests a dynamic web page, the HTML is generated by a. the web browser b. a database server c. an application server d. the web server
application server
The code that follows has a bug in it because the second use of the variable named salesTax is spelled with all lowercase letters (salestax). var calculateTax = function(subtotal,taxRate) { var salesTax = subtotal * taxRate; salestax = parseFloat(salesTax.toFixed(2)); return salesTax; } Assuming that there are no other problems and that you're using strict mode, what will happen when this code is executed? a. sales Tax will contain the right value, but it won't be rounded b. an error will occur because salestax hasn't been declared c. salestax will contain the rounded sales tax value d. salesTax will contain null when it is returned
b. an error will occur because salestax hasn't been declared
Given the following code, which of the following statements displays "John Smith is 29"? var employee = []; employee["name"] = "John Smith"; employee["age"] = 29; a.alert(employee[1] + " is " + employee[2]); b.alert(employee["name"] + " is " + employee["age"]); c.alert(employee["name"][0] + " is " + employee["age"][0]); d.alert(employee[0] + " is " + employee[1]);
b.alert(employee["name"] + " is " + employee["age"]);
Three of the common CSS selectors select a. by element type, id attribute, and class attribute b. h1, ul, and li elements c. div, h1, and p elements d. by element, header, and footer
by element type, id attribute, and class attribute
What does the following code do? var displayError = function ( message ) { alert("Error: " + message); } a. creates a function named message. b. creates a function named displayError. c. creates a function and stores it in a variable named displayError. d. calls a function named displayError.
c. creates a function and stores it in a variable named displayError.
Before you use a plugin, you have to know all but one of the following. Which one is it? a. the options that it provides b. the methods that it provides c. how its CSS works d. the HTML that it requires
c. how its CSS works
What property of the Radio object is used to determine if a radio button is selected? a. the selected property b. the checked property c. the radio property d. the value property
checked property
The easiest way to run a web page that's already in your browser after you've made changes to the code for the page is to a. type just the domain name into the address bar b. use the Open or Open File command in the File menu c. type just the file name into the address bar d. click on the reload or refresh button
click on the reload or refresh button
To view the changes that have been made to the DOM for a page by the JavaScript, you can a. display the HTML for the page in a browser b. display the HTML for the page in Chrome's Sources panel c. display the HTML for the page in Chrome's Elements panel d. none of the above
display the HTML for the page in Chrome's Elements panel
What does the following jQuery code do? $("h2").prev(); a. get the h2 element that precedes the current element b. gets the previous sibling of the selected h2 element that is an h2 element c. gets the element in the HTML that precedes the selected h2 element d. gets the previous sibling of the selected h2 element
gets the previous sibling of the selected h2 element
Which of the following is NOT part of an HTTP URL: a. protocol b. node c. path d. filename
node
To display data in a span element, you can use the firstChild property to get a pointer to the Text node. Then, what property of the Text node can you use to set the value that's displayed in the span element? a. the message property b. the text property c. the value property d. the nodeValue property
nodeValue property
The six data types allowed in JSON are strings, numbers, Booleans, arrays, objects, and a. integers b. undefined c. function definitions d. null
null
After you've coded the constructor for an object type, you can add a method to that object type by adding a function to its a. prototype object b. Object object c. Function object d. method property
prototype object
What object defines a pattern that can be searched for in a string? a. string b. match c. regular expression d. pattern
regular expression
var add = function (val1, val2, val3) { if ( arguments.length < 1 ) return 0; var sum = 0; for ( var i = 0; i < arguments.length; i++) { sum += arguments[i]; } return sum; } (Refer to code example 10-2.) If the function is called with this statement var sum = add(1); what happens? a. the function returns 1. b. the function returns 0. c. the function returns undefined. d. the function throws an error because sum is already defined.
the function returns 1
var add = function (val1, val2, val3) { if ( arguments.length < 1 ) return 0; var sum = 0; for ( var i = 0; i < arguments.length; i++) { sum += arguments[i]; } return sum; } (Refer to code example 10-2.) If the function is called with this statement alert (add(1,2,3,4,5)); what happens? a. the function returns 15. b. the function returns 0. c. the function returns undefined. d. the function returns 6.
the function returns 15.
What method of the Date object gets the day of the month in local time? a. the getDayOfMonth method b. the getDay method c. the getMonth method d. the getDate method
the getDate method
What method of the String object searches the string for an occurence of the specified search string? a. the substring emthod b. the charAt method c. the search method d. the indexOf method
the indexOf method
When a function is called as an event handler, its this keyword refers to a. the global object b. the first argument c. the argument array d. the object that raised the event
the object that raised the event
If a JavaScript object has a JSON method, and a replacer function is passed to the stringify method, a. the replacer function is called instead of the toJSON method. b. the toJSON method is called instead of the replacer function. c. the toJSON method is called and its return value is passed to the replacer function. d. the repalcer function is called and its return value is passed to the toJSON method.
the toJSON method is called instead of the replacer function. XXXX the toJSON method is called and its return value is passed to the replacer function
Which of the following statements about an array of arrays is true? a. an array of arrays must store a one-dimensional list of values. b. two indexes are used to access a value that's stored in an array of arrays c. Arrays can only be nested two deep. In other words, you can't have an array of arrays of arrays d. an associative array can't be used as an array within another array.
two indexes are used to access a value that's stored in an array of arrays.
Which method adds one or more elements to the beginning of an array? a. pop b. unshift c. shift d. push
unshift
Which of the following statements is NOT a valid way to create a date object named birthday? a. var birthday = new Date(1978, 11, 2) b. var birthday = "12/2/1978"; c. var birthday = new Date("12/2/1978"); d. var birthday = new Date();
var birthday = "12/2/1978";
In the jQuery for using a widget, you must code a selector followed by a. the name of the widget, the method to be called, and any options. b. the method to be called and any options c. the name of the widget and any options d. the method to be called, any options, and a callback function
the method to be called and any options