What will be the output of the following JavaScript code? [code] <p id="demo"></p> <script> function myFunction() { document.getElementByI

Trương Duy

New member
What will be the output of the following JavaScript code?
Code:
<p id="demo"></p>
<script>
function myFunction() 
{
     document.getElementById("demo").innerHTML = Math.trunc(8.76);
}
</script>
A. 8.70
B. 8.76
C. 8.00
D. Error
 
Answer: c
Explanation: The trunc() method returns the integer part of a number. This method will NOT round the number up/down to the nearest ingeger, but simply remove the decimals.
 

Tìm kiếm

Back
Top