<<-----: JavaScript Math Object :----->>
The JavaScript Math object allows you to perform mathematical task on numbers.
👉console.log(Math.PI);
console.log(Math.PI);
👉Math.round()
returns the value of x rounded to its nearest integer
let num = 10.44857;
console.log(Math.round(num));
👉Math.pow()
Math.pow(x,y) return the value of x to the power of y
console.log(Math.pow(2,3));
console.log(2**3);
👉Math.squr()
Math.sqrt() returns the square root of x
console.log(Math.sqrt(25));
console.log(Math.sqrt(36));
console.log(Math.sqrt(47));
console.log(Math.sqrt(58));
👉 Math.abs()
Math.abs(x) returns the absolute (positive) value of x
console.log(Math.abs(-55));
console.log(Math.abs(-55.5));
console.log(Math.abs(-955));
👉Math.ceil()
Math.ceil() returns the value of x rounded up to its nearest integer
It always increment your number if u add something after point(.).
console.log(Math.ceil(4.51));
console.log(Math.ceil(99.11));
👉Math.floor()
Math.floor() returns the value of x rounded down to its nearest integer
It always decrement your number if u add something after point(.).
console.log(Math.floor(4.67));
console.log(Math.floor(8.9));
👉Math.min()
Math.min() can be used to find the lowest value in a list of arguments
console.log(Math.min(45,67,324,345));
👉Math.max()
Math.max() can be used to find the higest value in a list of arguments
console.log(Math.max(45,67,324,345));
👉Math.random()
Math.random() returns a random numbre between 0 (inclusive), and 1
console.log(Math.floor(Math.random()*10)); // 0 to 9
👉Math.trunc()
The trunc() method returns the integer part of a number
console.log(Math.trunc(4.6));
console.log(Math.trunc(-9.1));
🏁 Practise Time :-
If the argument is a positive number, Math.trunc() is equivalent to
Math.floor(),
otherwise Math.trunc() is equivalent to Math.ceil().