What does
document.getElementById('menu') return, compared with document.querySelector('#menu')?- a
getElementByIdreturns a NodeList containing every element whose id matches, whilequerySelectorreturns just the first element it happens to find in the document - b
getElementByIdsearches by CSS selector, whilequerySelectorcan only search by an element's id - cBoth return the first matching element or
null, butgetElementByIdtakes an id whilequerySelectortakes any CSS selector✓ - d
getElementByIdis deprecated in favour ofquerySelector, so new code should never use it any more
Explanation:
getElementById looks up a single element by its id and returns that element or null; querySelector returns the first element matching any CSS selector (so '#menu' works too) or null. Neither returns a NodeList (a) — that is querySelectorAll. getElementById is not deprecated (d); it is perfectly idiomatic and slightly faster for plain id lookups.