Home > Sample chapters

Essential JavaScript and jQuery

Answers

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

Lesson 1

  1. Correct answer: C

    1. Incorrect: A property is a variable that’s defined on an object.
    2. Incorrect: A method is a function that’s defined on an object.
    3. Correct: A class is a blueprint for an object.
    4. Incorrect: An event takes place from external input, usually from user input.
  2. Correct answer: A

    1. Correct: The prototype is the starting object that is cloned when creating a new object.
    2. Incorrect: A property is a variable that’s defined on an object.
    3. Incorrect: A class is a blueprint for an object.
    4. Incorrect: An event takes place from external input, usually from user input.
  3. Correct answer: A

    1. Correct: You replace the prototype of the child object with a new instance of the parent object and then replace the prototype constructor with the child constructor.
    2. Incorrect: The createChild method is not a valid method.
    3. Incorrect: The setParent method is not a valid method.
    4. Incorrect: JavaScript does support inheritance by replacing the prototype of the child object with a new instance of the parent object and then replacing the prototype constructor with the child constructor.

Lesson 2

  1. Correct answer: B

    1. Incorrect: The use of the hash (#) symbol in the CSS selector indicates that you want to locate an element based on its id.
    2. Correct: The use of the period (.) in the CSS selector indicates that you want to locate the elements that match the CSS class name.
    3. Incorrect: Supplying a name for a CSS selector indicates that you want to locate the elements that have that tag name.
    4. Incorrect: The var hidden = $(‘class=Hidden’); syntax is invalid.
  2. Correct answer: A

    1. Correct: Using jQuery will help you create event-driven, browser-independent code.
    2. Incorrect: The code for creating and subscribing to events is browser-specific.
    3. Incorrect: You need to use JavaScript to write event-driven code.
    4. Incorrect: Use the jQuery library to write browser-independent code.
  3. Correct answer: C

    1. Incorrect: jQuery does not have an exists property.
    2. Incorrect: Even if no elements are found, jQuery will return a wrapper object.
    3. Correct: If no elements are found, the length property will be 0, which converts to a Boolean false.
    4. Incorrect: jQuery does not have a count property.