πŸ“Š JavaScript
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>
  • (A) 63.77
  • (B) 64
  • (C) 63
  • (D) 63.8
πŸ’¬ Discuss
βœ… 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

Explanation by: Mr. Dubey

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

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
275
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Ram Sharma
Publisher
πŸ“ˆ
94%
Success Rate