JavaScript MCQs – Browser APIs and Web Development

11.) What does the window.location object represent?

A) The browser’s history.
B) The URL of the current document.
C) The user’s geolocation.
D) The browser’s settings.

Answer: Option B

Explanation: The window.location object represents the current URL and allows navigation to different URLs.

12.) How do you create a new Web Worker in JavaScript?

A) new Worker()
B) createWorker()
C) Worker.create()
D) WebWorker()

Answer: Option A

Explanation: A new Web Worker is created using the new Worker() constructor, passing the path to the worker script.

13.) What does the FileReader API do?

A) Reads files from a remote server.
B) Deletes local files.
C) Writes data to local files.
D) Reads files from the local file system.

Answer: Option D

Explanation: The FileReader API reads files from the user’s local file system via input elements.

14.) Which method is used to trigger a custom event?

A) dispatchEvent()
B) triggerEvent()
C) fireEvent()
D) emitEvent()

Answer: Option A

Explanation: The dispatchEvent() method is used to trigger custom events programmatically.

15.) What is the purpose of the window.requestAnimationFrame() method?

A) To create animations.
B) To optimize animations by syncing with the screen refresh rate.
C) To stop animations.
D) To reload the page.

Answer: Option B

Explanation: The requestAnimationFrame() method schedules an animation frame for optimal rendering.

16.) How do you create a custom animation using the Web Animations API?

A) Use element.animate() method.
B) Use CSS.animate() method.
C) Use window.createAnimation() method.
D) Use animation.create() method.

Answer: Option A

Explanation: The Web Animations API’s element.animate() method creates and controls animations directly via JavaScript.

17.) What does the performance.now() method return?

A) The current time in milliseconds.
B) The time since the browser was opened.
C) The time since the page started loading.
D) The user’s system time.

Answer: Option C

Explanation: The performance.now() method returns the time in milliseconds since the page started loading.

18.) What does the IntersectionObserver API do?

A) Observes changes to DOM nodes.
B) Tracks visibility of elements within the viewport.
C) Monitors resizing of elements.
D) Observes HTTP requests.

Answer: Option B

Explanation: The IntersectionObserver API tracks the visibility of elements relative to the viewport.

19.) What is the purpose of the Blob object?

A) To represent binary data.
B) To compress data.
C) To create HTML elements.
D) To store cookies.

Answer: Option A

Explanation: The Blob object represents binary data, such as files or media.

20.) What is the purpose of the AbortController API in JavaScript?

A) stop animations on a webpage.
B) To cancel asynchronous operations like fetch().
C) To clear browser history.
D) To halt DOM rendering.

Answer: Option B

Explanation: The AbortController API allows you to cancel ongoing asynchronous operations such as fetch() by signaling the cancellation using the AbortSignal.

Leave a Reply

Your email address will not be published. Required fields are marked *