JavaScript MCQs – Browser APIs and Web Development

21.) What does the window.open() method do?

A) Reloads the current page.
B) Closes the current window.
C) Navigates to a new URL in the same window.
D) Opens a new browser tab or window.

Answer: Option A

Explanation: The window.open() method is used to open a new browser window or tab with the specified URL.

22.) How do you check the browser’s viewport width in JavaScript?

A) document.body.width
B) window.innerWidth
C) screen.width
D) viewport.size

Answer: Option B

Explanation: The window.innerWidth property returns the width of the browser’s viewport.

23.) What does the window.scrollTo() method do?

A) Adjusts the browser zoom level.
B) Saves the current scroll position.
C) Scrolls the document to a specific position..
D) Highlights the content on the page.

Answer: Option C

Explanation: The scrollTo() method scrolls the document to a specified set of coordinates.

24.) Which API is used to make WebSocket connections?

A) fetch()
B) WebSocket
C) HTTP
D) Ajax

Answer: Option B

Explanation: The WebSocket API provides a way to create and manage WebSocket connections for real-time communication.

25.) What does the Notification API do?

A) Sends notifications to the user’s email.
B) Displays browser notifications.
C) Tracks the user’s activity.
D) Updates the webpage title.

Answer: Option B

Explanation: The Notification API allows developers to display notifications in the browser.

26.) How can you monitor changes to the size of an element?

A) Using the ResizeObserver API.
B) Using the MutationObserver API.
C) Using the IntersectionObserver API.
D) Using the performance.now() method.

Answer: Option A

Explanation: The ResizeObserver API is specifically designed to monitor changes to the size of an element.

27.) What is the purpose of the Clipboard API?

A) To save user data locally.
B) To read and write data to the clipboard.
C) To access file data.
D) To modify the DOM.

Answer: Option B

Explanation: The Clipboard API provides methods to copy, paste, and modify data in the clipboard.

28.) How do you register an event that triggers once and then removes itself?

A) Use the once option in addEventListener().
B) Use addEventListener() followed by removeEventListener().
C) Use the triggerOnce() method.
D) Use the oneTimeEvent() function.

Answer: Option A

Explanation: The addEventListener() method supports a once option that ensures the event listener is triggered only once.

29.) What does the crypto.randomUUID() method do?

A) Generates a unique identifier.
B) Encrypts a string.
C) Decrypts a string.
D) Creates a random number.

Answer: Option A

Explanation: The crypto.randomUUID() method generates a universally unique identifier (UUID).

30.) How can you determine the type of device being used?

A) Using the device.check() method.
B) Using the window.deviceType property.
C) Using the screen.type property.
D) Using the navigator.userAgent property.

Answer: Option D

Explanation: The navigator.userAgent property provides information about the browser, operating system, and device type.

Leave a Reply

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