Q. What will be the output of the following JavaScript code?
Code:
< p id="demo">< /p>
< script>
var a = 63.786;
document.getElementById ("demo").innerHTML =a.toFixed(0)
< /script>
β
Correct Answer: (B)
64
Explanation:
Let's solve it carefully.
You have this JavaScript code:
<p id="demo"></p>
<script>
var a = 63.786;
document.getElementById("demo").innerHTML = a.toFixed(0);
</script>
- a.toFixed(0) means: round a to 0 decimal places.
- a = 63.786
- Rounding 63.786 to 0 decimal places gives 64.
So the correct answer is:
(B) 64