Master Your JavaScript Skills with This Quick Functions and Closures Quiz!

Test your JavaScript knowledge with this quick quiz! Covers function declarations vs function expressions, arrow functions, closures, scope, higher-order functions, and output-based questions.

Question 1.

What is the output of this code?

  • A.

    John

  • B.

    undefined

  • C.

    ReferenceError

  • D.

    null

Question 2.

Which of the following is a correct syntax for an arrow function?

  • A.

    const sum = (a, b) => { return a + b; }

  • B.

    const sum = (a, b) { return a + b; }

  • C.

    const sum => (a, b) => return a + b;

  • D.

    const sum = a, b => a + b;

Question 3.

What is the output of this closure example?

  • A.

    1 and 2

  • B.

    0 and 0

  • C.

    undefined

  • D.

    1 and 1

Question 4.

What is an IIFE in JavaScript?

  • A.

    A function with no parameters

  • B.

    A function that is hoisted

  • C.

    A function that calls itself automatically

  • D.

    A function with this context

Question 5.

What will be logged in the console?

  • A.

    Hello, Alice

  • B.

    undefined

  • C.

    Hello,

  • D.

    ReferenceError

Question 6.

What will console.log(sum); output?

  • A.

    undefined

  • B.

    TypeError

  • C.

    ReferenceError

  • D.

    5

Question 7.

What will happen here?

  • A.

    undefined

  • B.

    window or global object

  • C.

    null

  • D.

    Error

Question 8.

What is the output?

  • A.

    undefined

  • B.

    10

  • C.

    20

  • D.

    Error

Question 9.

Which higher-order function is used to transform each element of an array?

  • A.

    forEach()

  • B.

    filter()

  • C.

    reduce()

  • D.

    map()

Question 10.

What is the result of this code?

  • A.

    [2, 4, 6, 8]

  • B.

    [4, 8]

  • C.

    [2, 4]

  • D.

    [8, 4]