JavaScript Code Challenges: DOM, Events, and Promises

This quiz covers foundational topics in JavaScript, including:

  • Variable Hoisting and Scoping: Understanding the behavior of var, let, and const in different contexts.
  • Promises and Async/Await: Handling asynchronous operations effectively in JavaScript.
  • Array and Object Manipulation: Using methods like map, filter, and the spread operator for data transformation.

This will help you evaluate your understanding of JavaScript’s core concepts and strengthen your problem-solving skills!

Question 1.

What does this code output?

  • A.

    undefined

  • B.

    10

  • C.

    20

  • D.

    Throws an error

Question 2.

What happens when you run this code?

  • A.

    Adds an alert when the button with ID btn is clicked

  • B.

    Throws an error

  • C.

    Doesn't execute anything

  • D.

    Adds a console log instead of an alert

Question 3.

What will this code log to the console?

  • A.

    Throws an error

  • B.

    [1, 2, 3]

  • C.

    undefined

  • D.

    [2, 4, 6]

Question 4.

What will this code do?

  • A.

    Logs undefined

  • B.

    Logs "Success!" after 2 seconds

  • C.

    Logs "Success!" immediately

  • D.

    Throws an error

Question 5.

What will this code output?

  • A.

    {a: 1, b: 2}

  • B.

    1 2

  • C.

    undefined undefined

  • D.

    Throws an error

Question 6.

What will the following log?

  • A.

    [1, 2]

  • B.

    undefined

  • C.

    [1, 2, 3, 4]

  • D.

    Throws an error

Question 7.

What does this code log?

  • A.

    true true

  • B.

    false true

  • C.

    true false

  • D.

    false false

Question 8.

What will this function return?

  • A.

    Hello, !

  • B.

    undefined

  • C.

    Throws an error

  • D.

    Hello, Guest!

Question 9.

What will this code output?

  • A.

    2

  • B.

    1

  • C.

    Throws an error

  • D.

    undefined

Question 10.

What does this async function log?

  • A.

    undefined

  • B.

    Throws an error

  • C.

    Data fetched!

  • D.

    Logs nothing