What will be the Output of following Javascript
<script language=“Javascript”> javascript:function x(){ x=4+“4”; document.write(x); } x ( ) ; </script>- AOption (a)
44
- BOption (b)
8
- COption (c)
4
- DOption (d)
Error output
View answer & explanationHide answer & explanation
Correct answer
44
Why this answer is correct
The correct answer is option 1) 44
Key Points
- Code:
- Step-by-step Execution:
- 4 + "4" = JavaScript performs string concatenation when one operand is a string.
- 4 + "4" → "44" (number 4 is converted to a string and concatenated)
- The result is stored in x, which is now a variable, not a function anymore.
- document.write(x); writes "44" to the document.
- Note: JavaScript allows overwriting functions with variables due to its dynamic nature, so no runtime error occurs.
Additional Information
- In JavaScript, the + operator does numeric addition or string concatenation depending on operand types.
- Functions can be reassigned as variables unless declared with const or let in strict mode.
- The statement x = 4 + "4" replaces the function x() with a string value, but only after it is called.
Hence, the correct answer is: option 1) 44