Q:

Write a JavaScript program to convert a value to a safe integer

0

Write a JavaScript program to convert a value to a safe integer.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const toSafeInteger = num =>
  Math.round(Math.max(Math.min(num, Number.MAX_SAFE_INTEGER), Number.MIN_SAFE_INTEGER));

console.log(toSafeInteger('3.2'));
console.log(toSafeInteger(Infinity));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now