What is the difference between querySelector() and querySelectorAll()?
The key difference is that querySelector() returns only the first element that matches the specified selector, while querySelectorAll() returns all elements that match the selector as a static NodeList. Both methods accept the same CSS selector syntax, allowing you to select elements by tag name, class, ID, attribute, or more complex combinations. If no elements match the selector, querySelector() returns null, while querySelectorAll() returns an empty NodeList.