Q. What does setInterval() do?

  • (A) Calls a function repeatedly at specified intervals
  • (B) Runs code only once after delay
  • (C) Stops execution
  • (D) Loops through array
πŸ’¬ Discuss
βœ… Correct Answer: (A) Calls a function repeatedly at specified intervals
Explanation: setInterval repeatedly calls a function every given milliseconds.

Q. What is the role of clearTimeout()?

  • (A) Cancels a timer set by setTimeout()
  • (B) Stops event propagation
  • (C) Clears the event queue
  • (D) Stops the event loop
πŸ’¬ Discuss
βœ… Correct Answer: (A) Cancels a timer set by setTimeout()
Explanation: clearTimeout cancels a timeout previously established by setTimeout().

Q. Which method is used to add an event listener in JavaScript?

  • (A) addEventListener
  • (B) onEvent
  • (C) listenTo
  • (D) eventAttach
πŸ’¬ Discuss
βœ… Correct Answer: (A) addEventListener
Explanation: addEventListener attaches an event handler to an element.

Q. What is event delegation?

  • (A) Using a parent element to handle events for its children
  • (B) Delegating events to the OS
  • (C) Using multiple event listeners
  • (D) Broadcasting events
πŸ’¬ Discuss
βœ… Correct Answer: (A) Using a parent element to handle events for its children
Explanation: Event delegation allows a parent to handle events from its children.

Q. Which method is used to prevent the default action of an event?

  • (A) preventDefault()
  • (B) stopDefault()
  • (C) halt()
  • (D) cancelEvent()
πŸ’¬ Discuss
βœ… Correct Answer: (A) preventDefault()
Explanation: preventDefault() stops the browser’s default behavior for an event.

Q. Which method stops event propagation in the DOM?

  • (A) stopPropagation()
  • (B) preventDefault()
  • (C) cancelBubble()
  • (D) haltEvent()
πŸ’¬ Discuss
βœ… Correct Answer: (A) stopPropagation()
Explanation: stopPropagation() prevents the event from bubbling up the DOM tree.

Q. Which JavaScript property refers to the element that triggered the event?

  • (A) event.target
  • (B) event.source
  • (C) event.trigger
  • (D) event.origin
πŸ’¬ Discuss
βœ… Correct Answer: (A) event.target
Explanation: event.target refers to the actual element that initiated the event.

Q. Which function is used to delay execution of code by a given time?

  • (A) setTimeout()
  • (B) delay()
  • (C) wait()
  • (D) sleep()
πŸ’¬ Discuss
βœ… Correct Answer: (A) setTimeout()
Explanation: setTimeout executes code after a specified number of milliseconds.

Q. What is the main thread in JavaScript?

  • (A) The single thread where JavaScript code executes
  • (B) A thread that handles HTTP requests
  • (C) A parallel execution thread
  • (D) The UI thread
πŸ’¬ Discuss
βœ… Correct Answer: (A) The single thread where JavaScript code executes
Explanation: JavaScript is single-threaded; the main thread runs all JS code.

Q. How can you defer script execution until the DOM is loaded?

  • (A) Use defer attribute in script tag
  • (B) Use async attribute
  • (C) Put script at the top
  • (D) Wrap code in alert()
πŸ’¬ Discuss
βœ… Correct Answer: (A) Use defer attribute in script tag
Explanation: defer delays script execution until after HTML is fully parsed.