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

Returns a pseudo-random float between 0 and 1.

Math.random()

  • Math.random() is a JS topic. In plain words you use it for click Save in a form page. Don’t start with a slogan — start with that picture.
  • Smallest example: addEventListener('click', …). Type it, run it, and say what you see. If you can do that from memory, you know Math.random().
  • From the example next to this theory: Returns a pseudo-random float between 0 and 1.
  • Trap: listener on a node that gets replaced. Fix that before you talk about advanced JS.
  • Viva: what is Math.random()? Then show addEventListener('click', …). Then name the trap.

Technical Interview Tip: What is Math.random()? Show this: addEventListener('click', …). Trap: listener on a node that gets replaced.

Code Examples for Math.random()

Math.random() — working example

// Topic: Math.random()
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.random(): map then reduce on [1, 2, 3]. Say both prints.

How to Explain Math.random() to an Interviewer

What is Math.random()?

Used for click Save a form page Not just the heading

Give one small example of Math.random().

addEventListener('click', …) Returns a pseudo-random float between 0 and 1

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

listener on a node that gets replaced Show the fix

Where do you use Math.random()?

a form page click Save