Chapter 4 Review

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

How do you signal to the JavaScript interpreter that it should not waste time and memory resolving syntax errors within a file for you?

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

The is the ordered list maintained by a JavaScript processor containing all the procedures, such as functions, methods, or event handlers, that have been called but have not yet finished processing.

call stack

A breakpoint _____.

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

After you throw an exception, you use a statement to handle the error.

catch

What statement can you add to your code to effectively serve the same role as a breakpoint?

debugger

A load-time error _____.

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

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

window.alert

Explain what Strict mode is, how to implement it, and how it's useful in reducing coding errors.

In Strict mode, some features are removed from the JavaScript language, while other features require more stringent syntax. To request that JavaScript processors parse your code in Strict mode, you add the following statement to your code: "use strict";

In a JavaScript program, which of the following will cause a runtime error?

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

errors are problems in the design of a program that prevent it from running as you anticipate.

logic

What type of error occurs when the interpreter fails to recognize code?

syntax

What is the advantage of tracing errors using the window.alert() method? What is the advantage of using the console.log() method instead?

Answer: The window.alert() method lets you monitor values as they change during program execution. The console.log() method lets you trace a bug in your program by analyzing a list of values rather than by trying to interpret the values displayed in alert dialog boxes on a case-by-case basis

Which of the following statements causes a syntax error?

document.write(Available points: " + availPoints);

Which of the following pieces of information is passed as an argument from a throw statement to a catch statement?

error message

The Watch window in the debugger lets you monitor the value of a(n) during program execution.

expression

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.";

false

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.

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.

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

false

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!"); }

finally

Which of the following exception handling code executes regardless of whether its associated try block throws an exception?

finally { lNameValid = true; }

Which of the following for statements is logically incorrect?

for (var count = 10; count <= 0; count++) { document.write(count); }

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

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

When running a JavaScript program, removing a breakpoint _____.

requires clicking a highlighted line number in the browser console

When a JavaScript interpreter encounters a problem while a program is executing, that problem is called a(n) error.

runtime

One way to use the browser console to view the progression of the value of the totalPrice variable throughout a JavaScript program without impeding the program's operation is to add _____.

statements such as console.log("totalPrice with tax = " + totalPrice); after functions that mutate totalPrice

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.

step into, step over

Which command executes all the statements in the next function in browser debugging tools

step over

If you are using any of the major browser applications, you can access debugging tools that can track and find errors in HTML, CSS, and JavaScript code through the same pane that opens with the browser console.

true

In , some features are removed from the JavaScript language, while other features require more stringent syntax.

strict mode

Explain two different ways that a text editor specialized for web development can help you in preventing errors and debugging code.

A code editor designed for web development can highlight both errors in your HTML code and syntax errors in your JavaScript while you type, saving you the trouble of locating and fixing them later.

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

The siftFlour function is active at the current breakpoint.

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

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

Which of the following modes temporarily suspends, or pauses, program execution so that you can monitor values and trace program execution?

break

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

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

Suppose you suspect that there is a logic error in your JavaScript program. One way to locate a potential bug is to _____.

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

Which of the following statements writes the value of the selection variable to the console?

console.log(selection);

If you wish to observe how a single expression or variable value changes as your JavaScript program executes, the most efficient approach is to _____.

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


Set pelajaran terkait

PowerBI Interview questions 2023

View Set

COGNITIVE SAMPLES OF BEHAVIOR #1

View Set

Level D Unit 7: Choosing the right word

View Set

CIST 2351 PHP Final Chapter 9-15

View Set

Hinkle Chapter 27: Management of Patients with Coronary Vascular Disorders

View Set

Fluid and Electrolytes: Balance and Disturbance Part 6

View Set

Module 15: System and User Security

View Set

present perfect simple and continuous

View Set