Browser APIs play a crucial role in creating dynamic, user-friendly web applications in JavaScript. They provide built-in tools to interact with the browser, manipulate the DOM, handle events, work with multimedia, and use advanced features like geolocation and local storage. Understanding these APIs is essential for modern web development and interview preparation, as questions often focus on their usage and behavior.
1.) What does the document.querySelector() method do?
A) Selects the first matching element.
B) Selects all matching elements.
C) Creates a new DOM element.
D) Deletes an element from the DOM.
2.) Which method is used to store data in the browser’s local storage?
A) sessionStorage.setItem()
B) storeData()
C) browserData.set()
D) localStorage.setItem()
3.) How can you detect when the DOM is fully loaded?
A) Using the load event on the window object.
B) Using the DOMContentLoaded event on the document object.
C) Using the onready event.
D) Using the readyState property.
4.) What does the navigator.geolocation.getCurrentPosition() method do?
A) Retrieves the user’s current location.
B) Sets the user’s location.
C) Fetches the current time.
D) Updates the user’s address.
5.) What is the purpose of the fetch() API?
A) To fetch local files.
B) To make HTTP requests.
C) To fetch browser settings.
D) To fetch cookies.
6.) Which method is used to add an event listener to an element?
A) element.onEvent()
B) element.attachEvent()
C) element.addEventListener()
D) element.bindEvent()
7.) How can you remove an item from localStorage?
A) localStorage.removeItem()
B) localStorage.clearItem()
C) localStorage.delete()
D) localStorage.eraseItem()
8.) What does the history.pushState() method do?
A) Redirects to a new URL.
B) Fetches the current page title.
C) Clears the browser history.
D) Modifies the browser history without reloading the page.
9.) Which method is used to parse JSON data in JavaScript?
A) JSON.stringify()
B) JSON.parse()
C) JSON.read()
D) JSON.convert()
10.) How can you detect if cookies are enabled in the browser?
A) Check the navigator.cookieEnabled property.
B) Use the document.cookies property.
C) Call checkCookies() method.
D) Access the cookieStore API.
Related