Parameters or Arguments
The number to truncate.
The trunc() function returns only the integer portion of a number.
Math is a placeholder object that incorporates mathematical functions and constants of which trunc() is one of these functions.
console.log(Math.trunc(32.65)); console.log(Math.trunc(8.1)); console.log(Math.trunc(-4.2));
In this example, we have invoked the trunc() function the use of the Math class.
We have written the output of the trunc() feature to the internet browser console log, for demonstration purposes, to show what the trunc() feature returns.
The following will be output to the internet browser console log:
32 8 -4
In this example, the first output to the console log again 32 which is 32.65 truncated to an integer value.
The 2nd output to the console log again 8 which is 8.1 truncated to an integer value.
The 1/3 output to the console log back -4 which is -4.2 truncated to an integer value.