JS Built-ins
← Math215 / 215
Mathtruncintermediate

Math.trunc() β€” trunc(NaN) = NaN

πŸ“– Usage Example
// Remove fractional part (truncates towards zero)
Math.trunc(4.9)    // β†’ 4
Math.trunc(-4.9)   // β†’ -4

Use Math.trunc() to drop the decimal part of a number, always truncating towards zero unlike Math.floor().

Math.trunc()

Returns the integer part of a number by removing any fractional digits.

Challenge: Observe that Math.trunc(NaN) returns NaN.

πŸ’‘ Hints (1)
  • β€’ NaN has no integer part; Math.trunc propagates NaN