JavaScript: Closures And Statements Trivia Quiz

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Catherine Halcomb
Catherine Halcomb
Community Contributor
Quizzes Created: 1384 | Total Attempts: 6,220,249
Questions: 11 | Attempts: 220

SettingsSettingsSettings
JavaScript: Closures And Statements Trivia Quiz - Quiz

Questions on closures, groovy truth, control structures, miscellaneous. Abc


Questions and Answers
  • 1. 

    Unlike a method a closure can only take one parameter.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    A closure is very much like a method and can take any number of parameters.

    Rate this question:

  • 2. 

    When you return from a closure which is called by an iterative method, you stop the iteration process.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The iteration process continues on the remaining elements of the object that you are iterating over.

    Rate this question:

  • 3. 

    Groovy truth is identical to Java truth.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    There are subtle and important differences in truthiness between the two languages.

    Rate this question:

  • 4. 

    In Java the order of case branches within a switch statement is immaterial.

    • A.

      True

    • B.

      False

    Correct Answer
    A. True
    Explanation
    This is true because Java is very restrictive on the types that you can switch on.

    Rate this question:

  • 5. 

    The Groovy do statement is identical to Java's do statement.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    Groovy does not have a do statement (I don't know why).

    Rate this question:

  • 6. 

    Consider this Groovy method and its invocation: def foo() {  def m = [:]  m.a = 0  m.b = 1 } def val = foo() The variable val:

    • A.

      Is of type Map

    • B.

      Is undefined since foo has no return value

    • C.

      Is of type Integer since the last statement of foo is of type Integer

    Correct Answer
    C. Is of type Integer since the last statement of foo is of type Integer
    Explanation
    Here the return statement is implicitly the last statement.

    Rate this question:

  • 7. 

    (Fill in the blank) The _____ operator invokes the compareTo method of a class that implements the Comparable interface.

    Correct Answer
    <=>
    spaceship
    Explanation
    The spaceship operator is used to invoke the compareTo method of a class that implements the Comparable interface. This operator is typically used to compare two objects and determine their relative order.

    Rate this question:

  • 8. 

    Groovy does not have a way to test for reference equality.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    You test for reference equality by calling the is() method.

    Rate this question:

  • 9. 

    What does this code do? List numbers = [1,2,3,4] println numbers.collect{it * 2}

    • A.

      Prints a list of the first four even numbers

    • B.

      Prints four even numbers each on its own line

    • C.

      Prints the variable numbers itself

    Correct Answer
    A. Prints a list of the first four even numbers
    Explanation
    The collect() method returns a list of four even numbers to the println() method.

    Rate this question:

  • 10. 

    In JavaScript, the keyword _______ is used to declare a variable with block-level scope.

    Correct Answer
    let, Let, LET
    Explanation
    In JavaScript, let is used to declare variables with block-level scope. This means the variable is only accessible within the code block (defined by curly braces {}) where it is declared. This allows for better control over variable visibility and helps prevent accidental modification or conflicts in larger programs.

    Rate this question:

  • 11. 

    The Groovy for/in loop has the same syntax as Java's for/each loop.

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    for (x in collection) {} // Groovyfor (x: collection) {} // Java

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Oct 24, 2024
    Quiz Edited by
    ProProfs Editorial Team
  • Nov 27, 2013
    Quiz Created by
    Catherine Halcomb
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.