The doctype is the first line of a xml document that defines its type.
For a html document, it's:
<!DOCTYPE html>
Parser may require an EOL character
It's mandatory otherwise the browser will turn into quirks mode 1) and some library will not work as expected 2).
If you do a lighthouse check, it's also reported.
With javascript, you can check the mode with the compat mode
console.log(document.compatMode)
If its value is: