What will be the output of the following script command? document.write…

2017

What will be the output of the following script command? document.write (2+5+"8");

  1. A.

    258 / 258

  2. B.

    Error

  3. C.

    7 / 7

  4. D.

    78 / 78

Attempted by 265 students.

Show answer & explanation

Correct answer: D

In JavaScript, operator evaluation depends on operator precedence and associativity. The + operator has the same precedence and is left-associative, so the expression is evaluated from left to right in this case.

First, 2 + 5 = 7 (numeric addition).
Then, 7 + "8" involves a number and a string, so JavaScript performs type coercion and converts 7 to a string. This results in string concatenation: "7" + "8" = "78".

Hence, the output is 78.

Explore the full course: Up Lt Grade Assistant Teacher 2025