JavaScript Math
Math.abs()
abs() Finds the absolute value of x
function difference(a, b) {
return Math.abs(a - b);
}console.log(difference(3, 5));
output: 2
Math.ceil()
Using the Math.celi () method, a number is rounded to the nearest maximum number.Example:
console.log(Math.ceil(.95));
output: 1Math.floor()
Using the Math.floor () method, a number is rounded to the nearest lowest number. Example:
console.log(Math.floor(5.95));
output: 5Math.min()
Get LITON AHMED’s stories in your inbox
Join Medium for free to get updates from this writer.
Math.min () finds the lowest number
console.log(Math.min(2, 3, 1));
output: 1Math.max()
Math.max () finds the highest number
console.log(Math.max(1, 3, 2));
output: 3Math.random()
Math.random () Method is used to take any number between 0 and 1.
Example:
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}console.log(getRandomInt(3));
output: 0, 1 or 2
Math.round()
Math.round () method can be used to find the roundoff value of a number.
Example:
console.log(Math.round(0.9));
output: 1Math.sqrt()


