Math.trunc() — JS Technical Interview Questions & Answers

Removes the fractional part of a number.

Math.trunc()

  • Math.trunc() is a JS topic. In plain words you use it for a short Math.trunc example in a script in the browser. Don’t start with a slogan — start with that picture.
  • Smallest example: the smallest Math.trunc example you can type. Type it, run it, and say what you see. If you can do that from memory, you know Math.trunc().
  • From the example next to this theory: Removes the fractional part of a number.
  • Trap: only saying “Math.trunc” with no example. Fix that before you talk about advanced JS.
  • Viva: what is Math.trunc()? Then show the smallest Math.trunc example you can type. Then name the trap.

Technical Interview Tip: What is Math.trunc()? Show this: the smallest Math.trunc example you can type. Trap: only saying “Math.trunc” with no example.

Code Examples for Math.trunc()

Math.trunc() — working example

// Topic: Math.trunc()
const nums = [1, 2, 3];
const doubled = nums.map((n) => n * 2);
console.log(doubled);
console.log(doubled.reduce((a, b) => a + b, 0));

Math.trunc(): map then reduce on [1, 2, 3]. Say both prints.

How to Explain Math.trunc() to an Interviewer

What is Math.trunc()?

Used for a short Math.trunc example a script in the browser Not just the heading

Give one small example of Math.trunc().

the smallest Math.trunc example you can type Removes the fractional part of a number

What mistake do beginners make with Math.trunc()?

only saying “Math.trunc” with no example Show the fix

Where do you use Math.trunc()?

a script in the browser a short Math.trunc example