hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    What will be displayed in the browser page when the following code is included? < html> < body> < script type="text/javascript"&g
    Question

    What will be displayed in the browser page when the following code is included?
    < html>
    < body>
    < script type="text/javascript">
    document.write("Hello World!")
    < /script>
    < /body>
    < /html>

    A.

    Hello World!

    B.

    document.write("Hello World!")

    C.

    "Hello World!"

    D.

    Nothing will be displayed

    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.
    Important Key Points

    1. document.write() behavior: Inserts raw HTML/text into the document while the page is parsing.
    2. Render timing: Safe during initial load; using it after load can overwrite the entire document.
    3. Output vs literal: String quotes are not shown; only the string’s content is rendered.
    4. Modern practice: Prefer DOM methods (appendChild, textContent, etc.) over document.write() for maintainability.
    5. HTML context: Because the string has no tags, it appears as plain text.
    6. 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.

    Free Tests

    Free
    Must Attempt

    MPTET Varg 3 PRT Mock 01

    languageIcon English
    • pdpQsnIcon150 Questions
    • pdpsheetsIcon150 Marks
    • timerIcon150 Mins
    languageIcon English
    Free
    Must Attempt

    MPTET Varg 3 PRT CDP Subject Test 01

    languageIcon English
    • pdpQsnIcon20 Questions
    • pdpsheetsIcon20 Marks
    • timerIcon20 Mins
    languageIcon English
    Free
    Must Attempt

    UPTET Paper 2 Social Science : PYP Held on 23rd Jan 2022 (Shift 2)

    languageIcon English
    • pdpQsnIcon150 Questions
    • pdpsheetsIcon150 Marks
    • timerIcon150 Mins
    languageIcon English
    test-prime-package

    Access ‘UPSSSC’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    383k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow