This section covers the questions for JavaScript DOM and BOM to clear all your concepts.
Question 1
Which method is used to select an element by its ID?
getElementByClass()
getElementById()
querySelectorAll()
getById()
Question 2
What does document.querySelectorAll() return?
An array of elements
A single element
A NodeList
Undefined
Question 3
How do you change the inner text of an element in the DOM?
element.innerText = "New Text";
element.textContent = "New Text";
element.innerHTML = "New Text";
All of the above
Question 4
What does window.location.href return?
The browser's name
The URL of the current page
The history of visited pages
The cookies of the website
Question 5
What is the purpose of window.history.back()?
To navigate to the next page in history
To reload the current page
To navigate to the previous page in history
To clear the browser's history
Question 6
Which method is used to set a cookie?
document.cookie = "key=value";
window.setCookie()
navigator.cookie()
cookie.set()
Question 7
What will the following code output?
console.log(window.navigator.userAgent);
Browser and device information
URL of the current page
Cookies of the website
Undefined
Question 8
Which event is triggered when the DOM is fully loaded?
onload
DOMContentLoaded
load
domComplete
Question 9
How do you remove an element from the DOM?
element.remove();
element.delete();
element.destroy();
element.clear();
Question 10
What does window.alert() do?
Logs a message to the console
Shows a confirmation box
Displays an alert box with a message
Refreshes the browser
There are 10 questions to complete.