Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Name: Class: Date:

Chapter 04: Debugging and Error Handling

Solution Manual for JavaScript The Web Warrior Series 6th Edition
Vodnik Gosselin 1305078446 9781305078444
Full download link at:
Solution manual: https://testbankpack.com/p/solution-manual-for-javascript-the-web-
warrior-series-6th-edition-vodnik-gosselin-1305078446-9781305078444/
Test bank: https://testbankpack.com/p/test-bank-for-javascript-the-web-warrior-series-
6th-edition-vodnik-gosselin-1305078446-9781305078444/
True / False

1. Each time a program calls a procedure, the procedure is added to the top of the call stack, and then removed after it
finishes executing.
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 259

2. Syntax refers to the order in which various parts of a program run, or execute.
a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 213

3. For each error encountered, a browser's console displays a line number and a description of the error.
a. True
b. False
ANSWER: True
POINTS: 1
REFERENCES: 218

4. You log values to the console using the window.alert() method.


a. True
b. False
ANSWER: False
POINTS: 1
REFERENCES: 231

5. A breakpoint is a designation added to a specific statement in a program that causes program execution to pause when it
reaches that statement.
a. True
b. False
ANSWER: True
Cengage Learning Testing, Powered by Cognero Page 1
Name: Class: Date:

Chapter 04: Debugging and Error Handling

POINTS: 1
REFERENCES: 245
246

Multiple Choice

6. A ____ error occurs when the interpreter fails to recognize code.


a. logic b. syntax
c. web d. run-time
ANSWER: b
POINTS: 1
REFERENCES: 213

7. A ____ error occurs when the JavaScript interpreter encounters a problem while a program is executing.
a. run-time b. syntax
c. logic d. browser
ANSWER: a
POINTS: 1
REFERENCES: 214

8. A ____ error is a flaw in a program’s design that prevents the program from running as you anticipate.
a. compile-time b. syntax
c. logic d. run-time
ANSWER: c
POINTS: 1
REFERENCES: 215

9. When using the console.log() method to trace bugs, it can be helpful to use a ____ program.
a. script b. hub
c. tracing d. driver
ANSWER: d
POINTS: 1
REFERENCES: 232

10. The ____ is the ordered list maintained by a JavaScript processor containing all the procedures that have been called
but have not yet finished processing.
a. call queue b. call heap
c. call stack d. methods list
ANSWER: c
POINTS: 1
REFERENCES: 259

11. ____ allows programs to handle errors as they occur in the execution of a program.
a. Error coding b. Form validation

Cengage Learning Testing, Powered by Cognero Page 2


Name: Class: Date:

Chapter 04: Debugging and Error Handling

c. Input validation d. Exception handling


ANSWER: d
POINTS: 1
REFERENCES: 263

12. You enclose code that may contain an exception in a ____ statement.
a. throw b. catch
c. throws d. try
ANSWER: d
POINTS: 1
REFERENCES: 263

13. You use a ____ statement within a try block to specify an error message.
a. catch b. call
c. throw d. throws
ANSWER: c
POINTS: 1
REFERENCES: 264

14. After you throw an error, you use a ____ statement to handle the error.
a. try b. catch
c. handle d. capture
ANSWER: b
POINTS: 1
REFERENCES: 264

15. The rules of a programming language are known as its ____.


a. logic b. syntax
c. call stack d. console
ANSWER: b
POINTS: 1
REFERENCES: 213

16. A program's ____ is the order in which various parts of the program run, or execute.
a. logic b. syntax
c. call stack d. console
ANSWER: a
POINTS: 1
REFERENCES: 213

17. The console.log() debugging method results in messages ____.


a. written to the text of the document being debugged b. displayed in dialog boxes
c. displayed in the browser console d. available only to the JavaScript processor
ANSWER: c
Cengage Learning Testing, Powered by Cognero Page 3
Name: Class: Date:

Chapter 04: Debugging and Error Handling

POINTS: 1
REFERENCES: 231

18. The window.alert() debugging method results in messages ____.


a. written to the text of the document being debugged b. displayed in dialog boxes
c. displayed in the browser console d. available only to the JavaScript processor
ANSWER: b
POINTS: 1
REFERENCES: 225

19. The debugging tools built into modern browsers are especially useful in tracking down ____.
a. compile-time errors b. syntax errors
c. run-time errors d. logic errors
ANSWER: d
POINTS: 1
REFERENCES: 242

20. ____ is the temporary suspension of program execution so you can monitor values and trace program execution.
a. The call stack b. Break mode
c. Debugging d. Tracing
ANSWER: b
POINTS: 1
REFERENCES: 245

21. After you evaluate code for exceptions, you can use a ____ statement to perform cleanup or necessary tasks.
a. try b. throw
c. catch d. finally
ANSWER: d
POINTS: 1
REFERENCES: 265

22. Which of the following JavaScript statements works like a breakpoint?


a. break; b. "use strict";
c. debugger; d. console.log();
ANSWER: c
POINTS: 1
REFERENCES: 276

23. Which of the following JavaScript statements requests that processors remove some features from the language and
require more stringent syntax for other features?
a. break; b. "use strict";
c. debugger; d. console.log();
ANSWER: b
POINTS: 1
Cengage Learning Testing, Powered by Cognero Page 4
Name: Class: Date:

Chapter 04: Debugging and Error Handling

REFERENCES: 276

24. An infinite loop is an example of a(n) ____ error.


a. syntax b. run-time
c. logic d. user
ANSWER: c
POINTS: 1
REFERENCES: 215

25. Writing values directly to the console is known as ____.


a. logging b. writing
c. stepping out d. breaking
ANSWER: a
POINTS: 1
REFERENCES: 231

Completion

26. ____________________ is the examination of individual statements in an executing program.


ANSWER: Tracing
POINTS: 1
REFERENCES: 225

27. The term ____________________ refers to the temporary suspension of program execution so that you can monitor
values and trace program execution.
ANSWER: break mode
POINTS: 1
REFERENCES: 245

28. You implement custom error handling using the ____________________ event.
ANSWER: error
onerror
POINTS: 1
REFERENCES: 270

29. In ____________________ mode, some features are removed from the language, while other features require more
stringent syntax.
ANSWER: strict
POINTS: 1
REFERENCES: 276

30. ____________________ is the process of tracing and resolving errors in a program.


ANSWER: Debugging
POINTS: 1
REFERENCES: 212
Cengage Learning Testing, Powered by Cognero Page 5
Name: Class: Date:

Chapter 04: Debugging and Error Handling

Matching

Match each item with a statement below:


a. syntax errors
b. error messages
c. window.alert()
d. driver program
e. breakpoint
f. bug
g. variables list
h. watch list
i. bulletproofing
j. commenting out
REFERENCES: 213
218
225
232
245
253
263
236

31. A list of expressions whose values are displayed and updated throughout the execution of a program
ANSWER: h
POINTS: 1

32. A statement in the code at which program execution enters break mode
ANSWER: e
POINTS: 1

33. Displays a value in a dialog box


ANSWER: c
POINTS: 1

34. Displays all local variables within the currently executing function, regardless of whether they have been initialized
ANSWER: g
POINTS: 1

35. Identifying lines you think maybe causing problems and transforming them into comments
ANSWER: j
POINTS: 1

36. Any error in a program that causes it to function incorrectly


ANSWER: f
POINTS: 1
Cengage Learning Testing, Powered by Cognero Page 6
Name: Class: Date:

Chapter 04: Debugging and Error Handling

37. Writing code that anticipates and handles potential problems


ANSWER: i
POINTS: 1

38. Caused by incorrect use of JavaScript code or references to objects, methods, and variables that do not exist
ANSWER: a
POINTS: 1

39. The first line of defense in locating bugs in JavaScript programs


ANSWER: b
POINTS: 1

40. A JavaScript program that contains only the code you are testing
ANSWER: d
POINTS: 1

Subjective Short Answer

41. What is the difference between syntax errors and run-time errors?
ANSWER: Run-time errors differ from syntax errors in that they do not necessarily represent JavaScript language
errors. Instead, run-time errors occur when the interpreter encounters code that it cannot execute. For
example, consider the statement createRecommendation();, which calls a custom JavaScript
function. This statement does not generate a syntax error, because it is legal (and usually necessary) to
create and then call custom functions in a JavaScript program. However, if your program includes the
call statement but does not include code that creates the function in the first place, your program
generates a run-time error. The error occurs when the interpreter attempts to call the function and is
unable to find it.
POINTS: 1
REFERENCES: 214

42. Briefly explain how to use comments to locate bugs with JavaScript.
ANSWER: Another method of locating bugs in a JavaScript program is to identify lines that you think may be
causing problems and transform them into comments. To do so, you simply add // to the start of a
single line, or /* to the start of a block and */ to the end of the block, just as you would to create any
other comment. This process is known as commenting out code. This technique can help you isolate a
particular statement that may be causing an error. In some cases, you may choose to comment out
individual lines that may be causing an error, or you may choose to comment out all lines except the
lines that you know work. When you first receive an error message, you can start by commenting out
only the statement specified by the line number in the error message. You can then save the document,
and then open it again in your browser to see if you receive another error. If you receive additional
error messages, you comment out those statements as well. Once you eliminate the error messages, you
can examine the commented out statements for the cause of the bug.
POINTS: 1
REFERENCES: 236
237

43. Explain the three stepping options found in the debugging tools in modern browsers.
Cengage Learning Testing, Powered by Cognero Page 7
Name: Class: Date:

Chapter 04: Debugging and Error Handling

ANSWER: The debugging tools in all three browsers include a set of alternative options known as stepping options,
which allow you to continue program execution after you enter break mode. The first, known as stepping
in or stepping into, executes an individual line of code and then pauses until you instruct the debugger to
continue. This feature gives you an opportunity to evaluate program flow and structure as code is being
executed.
As you use the Step Into button to move through code, the debuggers stop at each line within every
function of the JavaScript program. However, when stepping through a program to trace a logical error,
it is convenient to be able to skip functions that you know are functioning correctly. The second option,
known as stepping over, allows you to skip function calls. The program still executes each function that
you step over, but it appears in each debugger as if a single statement executes.
The final option, stepping out, executes all remaining code in the current function. If the current function
was called from another function, all remaining code in the current function executes and the debugger
stops at the next statement in the calling function.

POINTS: 1
REFERENCES: 251

44. Explain how access to the call stack is useful in debugging.


ANSWER: The call stack 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.
Each time a program calls a procedure, the procedure is added to the top of the call stack, and then
removed after it finishes executing.
The ability to view a list showing the contents of the call stack is very useful when tracing logic errors in
large programs with multiple functions. For example, suppose that you have a variable that is passed as
an argument among several functions. Suppose also that the variable is being assigned the wrong value.
Viewing the call stack, along with using tracing commands, makes it easier to locate the specific
function causing the problem.

POINTS: 1
REFERENCES: 259
260

45. Describe two advantages of implementing custom error handling.


ANSWER: Custom error handling allows programmers to write user-friendly messages. It also gives them greater
control over any errors that occur in their programs.
POINTS: 1
REFERENCES: 270

46. Name two tools you can use to analyze your HTML code for errors, and describe how to use them for this task.
ANSWER: One tool is an editor specialized for web development, such as Notepad++, Aptana Studio, or
KomodoEdit. These editors, and others like them, automatically highlight syntax errors in HTML, CSS,
and JavaScript code as you type. This means that rather than needing to scrutinize each line of code, you
can count on the editor to draw your attention visually to any errors it identifies—often even before you
test your code.
Another tool for automatically examining your code is the W3C Markup Validation
Service (http://validator.w3.org). Many validation errors also cause problems in the browser, so
validating your HTML and fixing any issues the validator identifies can help you remove bugs in your
HTML code, while at the same time helping you ensure that your HTML works across browsers.

POINTS: 1
Cengage Learning Testing, Powered by Cognero Page 8
Name: Class: Date:

Chapter 04: Debugging and Error Handling

REFERENCES: 272

47. Explain how strict mode can be useful in debugging.


ANSWER: While coding in strict mode may in fact generate more errors, it can be a helpful debugging tool. Many
of the features that strict mode prohibits or requires to be used in a certain way are well known for
causing hard-to-find bugs in code that implements them using nonstrict syntax.
For debugging purposes, it can be useful to develop and test all your code using strict mode. This not
only helps you notice issues in your code that may be causing problems, but it also helps you strengthen
your coding techniques to use current best practices, rather than relying on some parts of the language
that are still technically part of the specification but whose use is not generally recommended.

POINTS: 1
REFERENCES: 276

48. What is a dependency and what role do dependencies play in debugging?


ANSWER: Any program longer than a handful of lines includes statements that depend on the successful execution
of other statements or functions. These relationships, known as dependencies, can add an extra layer of
complexity to debugging. An error that seems to be caused by code in one function, for example, can
actually be the result of an error in another part of your program. In addition, an error in one part of your
code can stop dependent code from executing, preventing you from receiving error messages for the
dependent code. After finding and fixing a bug, it’s important to test related functionality that worked
correctly before the bug fix. In some cases, fixing one bug exposes another, or itself creates another
problem, so it’s important not to assume that everything that worked before fixing a bug will continue to
work after fixing it.

POINTS: 1
REFERENCES: 241

49. How is setting breakpoints useful in debugging?


ANSWER: A breakpoint is a designation added to a specific statement in a program that causes program execution
to pause when it reaches that statement. Once a program is paused at a breakpoint, you can use command
buttons within each window to trace program execution.
When a program is paused at a breakpoint, browser debugging tools display different types of
information about the current state of the program. Multiple breakpoints provide a convenient way to
pause program execution at key positions in your code at which you think there may be a bug.
POINTS: 1
REFERENCES: 246
247

50. What is the difference between a variables list and a watch list in browser debugging tools?
ANSWER: The debugging tools in all browsers display lists of local variables within the currently
executing function, regardless of whether they have been initialized. The variables lists help you see how
different values in the currently executing function affect program execution. In addition, each browser
lets you create a watch list, which is a list of expressions whose values are displayed and updated
throughout the execution of the program.

POINTS: 1
REFERENCES: 253

Cengage Learning Testing, Powered by Cognero Page 9


Name: Class: Date:

Chapter 04: Debugging and Error Handling

Cengage Learning Testing, Powered by Cognero Page 10

You might also like