Web Dev 2 Chapter 4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

When you discover that several variables are assuming inappropriate values at some point in your long, complex JavaScript program but don't know where or how this is happening, you should _____. A. examine the syntax for load-time and runtime errors B. open your debugger's Scope window to watch how the values change as the program executes C. use the Watch buttons in your debugger to pause and resume program execution at breakpoints D. insert alerts that will display the variables' values at various points in the program using the window.alert() method

B. open your debugger's Scope window to watch how the values change as the program executes

Suppose you see the following lists of functions in the call stack window of your browser's debugger as you are examining your JavaScript code. What does this call stack information indicate? siftFlour prepareBatter bakeCupcakes A. The bakeCupcakes function contains an error. B. The prepareBatter function calls the bakeCupcakes function. C. The siftFlour function is active at the current breakpoint. D. The bakeCupcakes function has called both the prepareBatter and siftFlour functions.

C. The siftFlour function is active at the current breakpoint.

When running a JavaScript program, removing a breakpoint _____. A. always alters the code B. degrades performance C. requires clicking a highlighted line number in the console D. should trigger a debugging pass to ensure no bugs were introduced

C. requires clicking a highlighted line number in the console

If the following statement appears in a JavaScript program, and the current value of x at that point is 12, the program will halt if the statement is within the try statement of a try catch block but continue execution if it is not. if (x > 10) throw "This value must be less than 10."; - True - False

- False

When adding a try catch statement to a JavaScript program, you can place the statements to execute if an error is not encountered in the blank shown in this code snippet. try { if (!(quantityBox.value > 0)) throw "Enter a quantity of at least 1"; _____ } catch(error) { messageElement.innerHTML = error; messageHeadElement.innerHTML = ""; } - True - False

- True

Imagine that you are writing a JavaScript program to display the line items, before-tax discount, sales taxes, and total price for a user's order. An error in this program is classified as a logic error when it _____. A. causes the discount to be applied after the taxes are added to the price, making the total price incorrect B. involves an illegal mathematical operation during the total price calculation C. prevents the program from being successfully loaded by the browser D. halts program execution before all page elements are displayed by the browser

A. causes the discount to be applied after the taxes are added to the price, making the total price incorrect

If you wish to observe how a single expression or variable value changes as your JavaScript program executes, the most efficient approach is to _____. A. copy one instance of it to the Clipboard, then paste it into the debugger's Watch window B. open the debugger's Scope window and select it within this window C. use the debugger to add breakpoints at each spot where you suspect it changes, then step through execution D. display the call stack within the debugger, then search for instances of it within the results

A. copy one instance of it to the Clipboard, then paste it into the debugger's Watch window

Imagine that you are trying to locate some logic errors in a JavaScript program using your browser console's debugging tools. You can use the "_____" button to trace a function step by step, or the "_____" button to run a function without evaluating it in detail. A. step into, step over B. step into, step out C. step over, step into D. step out, step over

A. step into, step over

Suppose you want to add the following statement to your JavaScript code in order to help you trace an error. What belongs in the blank? _____("totalPrice = " + totalPrice); A. window.alert B. window.debug C. use strict D. case

A. window.alert

Which statement about this error handling function is correct? function handleErrors(message, url, line) { console.log("The page " + url + " produced the error " + message + "on line " + line); return false; } ​ A. This function replaces the browser's default error handling. B. This function supplements but does not override the browser's default error handling. C. This function contains syntax errors. D. The optional parameters sometimes used for error handling functions are omitted.

B. This function supplements but does not override the browser's default error handling.

A load-time error _____. A. occurs when a browser attempts to run a JavaScript statement B. will result from a syntax mistake such as a misspelled JavaScript keyword C. may be caused by a JavaScript function that uses an undeclared variable D. is represented by the browser console message: Uncaught ReferenceError: amt is not defined.

B. will result from a syntax mistake such as a misspelled JavaScript keyword

How do you signal to the JavaScript interpreter that it should not waste time and memory resolving syntax errors within a file for you? A. View the file in the debugging mode of the web browser. B. Call the strictMode() method on the document element. C. Insert the text string "use strict"; as the first line of the file. D. This is unnecessary because the interpreter, by default, allows no departures from syntax rules.

C. Insert the text string "use strict"; as the first line of the file

In a JavaScript program, which of the following will cause a runtime error? A. omitting a closing curly brace from the end of a function B. placing statements that must be executed in the wrong order C. attempting to use a variable defined within one function to perform calculations in a different function D. attempting to use a variable with global scope to perform calculations within a function

C. attempting to use a variable defined within one function to perform calculations in a different function

Which statement about how JavaScript compares with other common programming languages is true? A. JavaScript requires stricter adherence to syntax than C++. B. Whereas using C++ requires strict adherence to syntax, Java and JavaScript are more forgiving. C. JavaScript, Java, and C++ are all similar in their degree of syntax strictness. D. Java and C++ will reject code that departs from syntax rules, whereas the JavaScript interpreter will run code even with errors.

D. Java and C++ will reject code that departs from syntax rules, whereas the JavaScript interpreter will run code even with errors.

A breakpoint _____. A. is inserted by adding the break keyword to end of a line of JavaScript code B. can be added to the beginning of a JavaScript program to run the interpreter in strict mode C. triggers the browser console to write messages about the state of the program to its log D. can be inserted by clicking a source code line number within the browser console

D. can be inserted by clicking a source code line number within the browser console

Suppose you suspect that there is a logic error in your JavaScript program. One way to locate a potential bug is to _____. A. log the results of a line to the console by enclosing it between /* and */ B. log the results of a line to the console by adding console.log to its beginning C. comment out a line by adding */ to its beginning and observe how this changes the results D. comment out a line by adding // to its beginning and observe how this changes the results

D. comment out a line by adding // to its beginning and observe how this changes the results

If you would like to display the "You have excellent taste in shoes!" message regardless of whether or not the following JavaScript code finds an error, what belongs in the blank? try { shoeSize = document.getElementById("sizeBox").value; if (shoeSize === "") throw "Size missing"; } catch(err) { window.alert("Please enter a shoe size."); } _____ { window.alert("You have excellent taste in shoes!"); } ​ A. catch(err2) B. else C. return D. finally

D. finally

When you anticipate that a user error may occur during the execution of a set of JavaScript statements, you can handle potential errors by placing them within a catch command block. - True - False

- False

When you open a JavaScript file with your browser's console for debugging, the console will highlight all syntax errors in the file for you immediately. - True - False

- False

You can correct an error in a JavaScript program by creating an event listener that runs a function, for instance by adding window.addEventListener("error", handleErrors). - True - False

- False


Kaugnay na mga set ng pag-aaral

Iowa Laws, Rules, and Regulations Pertinent to Health Only

View Set

Motor Learning and Performance Chapter 8

View Set

MUS 108: Exam #3, Ch. 21-27 Except 24

View Set

IGGY Chapter 26: Care of Patients with Burns

View Set

Astronomy Practice Quiz 4 (Canvas)

View Set

Ch 6 quiz - Integumentary System

View Set