Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

134 CHAPTER 3 Getting started with JavaScript


Answers


This section contains the answers to the lesson review questions in this chapter.

Lesson 1



  1. Correct answer: C
    A. Incorrect: The undefined value means that the variable has never been initialized.
    B. Incorrect: The null value means that the variable was explicitly set to have no
    value.
    C. Correct: When performing a mathematical operation on a nonnumeric value, NaN
    (not a number) will result.
    D. Incorrect: The Infinity value will result when your value exceeds
    1.7976931348623157E + 10308.

  2. Correct answers: B, C, D, and F
    A. Incorrect: You cannot use a JavaScript keyword for a variable name, and switch is a
    JavaScript keyword.
    B. Correct: The myChar variable name is valid.
    C. Correct: JavaScript allows a variable name to contain the dollar sign, so the $cost
    variable name is valid.
    D. Correct: JavaScript allows a variable name to contain the underscore, so the _total
    variable name is valid.
    E. Incorrect: Variable names cannot begin with a number.
    F. Correct: Variable names can contain numbers but cannot begin with a number.

  3. Correct answer: B
    A. Incorrect: The use of ?? causes a syntax error.
    B. Correct: The use of || causes Valid User to be displayed if userName has no value.
    C. Incorrect: The use of && displays nothing if userName has no value.
    D. Incorrect: The use of + causes Valid User to be displayed if userName has no value,
    but it also displays the userName and Valid User together when the userName has
    a value.


Lesson 2



  1. Correct answer: B
    A. Incorrect: QUnit is for testing JavaScript for the web, not Windows 8.
    B. Correct: QUnit-Metro is a variation of QUint, which supports Windows 8.

Free download pdf