[{"id":"htmladvanced-001","courseId":"html-advanced","domain":"document-structure","topic":"Encoding sniffing order","prompt":"A browser's sniffing step picks an encoding for a page, but a meta tag later in the file declares a different one. When does the parser need to change encodings?","hint":"Think about when the first guess about encoding could be wrong.","explain":"The browser first guesses how to decode the bytes, and that guess can be wrong. A meta element found later can name another encoding, and the parser then has rules for whether and when it may switch.","source":"https://html.spec.whatwg.org/multipage/parsing.html#determining-the-character-encoding","interaction":{"type":"single"},"options":[{"id":"a","text":"When sniffing found no encoding, or found one that is not the file's actual encoding.","why":"The change happens in those cases, when a meta element declares a new encoding."},{"id":"b","text":"Always, because a meta tag overrides whatever encoding the browser sniffed.","whyNot":"Not always: when the current encoding is UTF-16BE or UTF-16LE, a meta declaration is ignored."},{"id":"c","text":"Only when the HTTP Content-Type header omits a charset.","whyNot":"The change algorithm runs only when a meta element declares a new encoding, so the HTTP header is not the trigger."},{"id":"d","text":"Never; once the first bytes are decoded, the encoding is fixed for the whole file.","whyNot":"The parser can change encodings while parsing, so the first decoding is not final."}],"answer":"a","explanation":"The parser may change encoding mid-parse when sniffing failed or picked the wrong encoding, and only a meta element declaring a new encoding triggers this.","concept":"The parser may change encoding mid-parse when sniffing failed or picked the wrong encoding, and only a meta element declaring a new encoding triggers this.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["A wrong encoding guess can be corrected mid-parse, but only through a meta declaration."]},{"id":"htmladvanced-002","courseId":"html-advanced","domain":"document-structure","topic":"Old doctype and quirks mode","prompt":"A page with an old layout is rendering in quirks mode. A script reads document.compatMode. Which value does it get?","hint":"Think about which legacy behavior the browser is emulating.","explain":"Browsers render a page in one of several modes. Quirks mode copies old browser behavior, while the standards modes follow modern specifications. A script can read the active mode from a property on document.","source":"https://developer.mozilla.org/en-US/docs/Web/HTML/Guides/Quirks_mode_and_standards_mode","interaction":{"type":"single"},"options":[{"id":"a","text":"BackCompat","why":"compatMode is BackCompat exactly when the document is in quirks mode."},{"id":"b","text":"CSS1Compat","whyNot":"That value means the document is not in quirks mode."},{"id":"c","text":"Quirks","whyNot":"compatMode never reports that word; its only values are BackCompat and CSS1Compat."},{"id":"d","text":"NoQuirks","whyNot":"No such value exists; a document outside quirks mode reports CSS1Compat."}],"answer":"a","explanation":"document.compatMode is 'BackCompat' in quirks mode and 'CSS1Compat' otherwise.","concept":"document.compatMode is 'BackCompat' in quirks mode and 'CSS1Compat' otherwise.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["document.compatMode returns BackCompat in quirks mode and CSS1Compat otherwise."]},{"id":"htmladvanced-003","courseId":"html-advanced","domain":"document-structure","topic":"DOMContentLoaded timing","prompt":"A page has a deferred script, a module script and an async script. Put these page-load moments in the order they happen.","hint":"Ask which scripts DOMContentLoaded waits for, and which it does not.","explain":"Scripts do not all run at the same moment during page load. A script's attributes decide when it runs relative to parsing and to the DOMContentLoaded event. Consider what each kind of script waits for.","source":"https://developer.mozilla.org/en-US/docs/Web/API/Document/DOMContentLoaded_event","interaction":{"type":"sort","items":[{"text":"The HTML parser finishes, and document.readyState becomes \"interactive\".","why":"Parsing ends first; readyState becomes interactive before any defer or module script runs."},{"text":"Deferred and module scripts execute.","why":"They run once parsing is done, and DOMContentLoaded fires only after they have run."},{"text":"The DOMContentLoaded event fires.","why":"It fires after the deferred and module scripts, but before async scripts execute."},{"text":"Async scripts execute.","why":"They run after DOMContentLoaded has fired, because that event does not wait for async scripts."},{"text":"document.readyState becomes \"complete\".","why":"It is set only after the async scripts have executed, so it comes last."}]},"options":[],"answer":"o:abcde","explanation":"DOMContentLoaded waits for parsing and deferred or module scripts but not async scripts, and readyState becomes complete after async scripts run.","concept":"DOMContentLoaded waits for parsing and deferred or module scripts but not async scripts, and readyState becomes complete after async scripts run.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["DOMContentLoaded does not wait for async scripts; readyState becomes complete last."]},{"id":"htmladvanced-004","courseId":"html-advanced","domain":"document-structure","topic":"document.write during parsing","prompt":"A script running in an XML document calls document.writeln() to add a paragraph to the page. What happens?","hint":"Check which kind of document the script is running in.","explain":"document.write and writeln add text to the parser's input while a page loads. Their behavior depends on the kind of document they run in and on the state of the parser.","source":"https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#dom-document-write","interaction":{"type":"single"},"options":[{"id":"a","text":"It throws an InvalidStateError DOMException.","why":"writeln throws InvalidStateError when it is invoked on XML documents."},{"id":"b","text":"It inserts the paragraph at the insertion point, as it does in an HTML page.","whyNot":"The write steps throw for XML documents before any text is inserted."},{"id":"c","text":"It returns quietly and the paragraph is dropped.","whyNot":"The steps throw an exception for XML documents; they do not return quietly."},{"id":"d","text":"It appends the paragraph to the end of the body after loading.","whyNot":"writeln has no such append behavior; the XML check fails first with an exception."}],"answer":"a","explanation":"document.writeln() throws an InvalidStateError DOMException when invoked on XML documents.","concept":"document.writeln() throws an InvalidStateError DOMException when invoked on XML documents.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","code":"document.writeln(\"<p>Hi</p>\");","takeaways":["document.write and writeln are strongly discouraged, and writeln throws on XML documents."]},{"id":"htmladvanced-005","courseId":"html-advanced","domain":"document-structure","topic":"Foster parenting in tables","prompt":"While the parser is inside a table, a script removes that table from the document. Misnested text then arrives. What does the foster-parenting step do?","hint":"Consider what the parser can assume about an element it inserted earlier.","explain":"When content is misnested inside a table, the parser must choose an insertion point other than the table. The choice depends on the open elements and on where the table currently sits in the document.","source":"https://html.spec.whatwg.org/multipage/parsing.html#foster-parenting","interaction":{"type":"single"},"options":[{"id":"a","text":"It checks the table's current parent and inserts there; if the table has been removed, it uses the element above the table in the stack.","why":"The steps recheck the table's live position and fall back to the element above it in the stack when it has no parent."},{"id":"b","text":"It inserts the text into the table's first cell, ignoring the removal.","whyNot":"Foster parenting never targets a cell; it targets the table's parent or the element above the table."},{"id":"c","text":"It stops parsing and throws, because the table it expected is gone.","whyNot":"The parser recovers by choosing a target; the steps do not abort because a table was removed."},{"id":"d","text":"It discards the text, because a removed table has nothing to hold it.","whyNot":"The steps always return a target to insert into, so the text is not discarded."}],"answer":"a","explanation":"Foster parenting re-checks the table's current parent, and falls back to the element above the table in the stack when the table has been removed from the DOM.","concept":"Foster parenting re-checks the table's current parent, and falls back to the element above the table in the stack when the table has been removed from the DOM.","rev":1,"updatedAt":"2026-10-23","kind":"scenario","takeaways":["Scripts can move or remove a table mid-parse, so the parser checks where the table is now."]}]