Correct option is A
document.write() writes the provided string directly into the HTML document at the point the script executes.
Here, the script runs during page load (in the <body>), so the text content Hello World! is inserted into the page.
No quotation marks are rendered because they are part of the JavaScript string literal, not the output.
Option (b) would display the code itself, which doesn’t happen here.
Option (c) includes quotes, which are not printed.
Option (d) is wrong because document.write() does produce output during load.
No quotation marks are rendered because they are part of the JavaScript string literal, not the output.
Option (b) would display the code itself, which doesn’t happen here.
Option (c) includes quotes, which are not printed.
Option (d) is wrong because document.write() does produce output during load.
Important Key Points
- document.write() behavior: Inserts raw HTML/text into the document while the page is parsing.
- Render timing: Safe during initial load; using it after load can overwrite the entire document.
- Output vs literal: String quotes are not shown; only the string’s content is rendered.
- Modern practice: Prefer DOM methods (appendChild, textContent, etc.) over document.write() for maintainability.
- HTML context: Because the string has no tags, it appears as plain text.
- Placement: Being inside <body> ensures the output appears in the visible page flow.
Knowledge Booster
- Why (b) is wrong: That would require the browser to treat the code as text (e.g., escaped or inside <xmp>/<pre>), not as executable script.
- Why (c) is wrong: Quotes only exist in the JavaScript source, not in the rendered output.
- Why (d) is wrong: document.write("Hello World!") executed during parsing will always insert content; “nothing” would occur only if the script never ran or output was cleared later.