const num = 3.141592653589793238;
// Rounding down the first decimal
// 3.1 = 3, -1.1 =-2
console.log("Floor ", Math.floor(num));
console.log("Ceil ", Math.ceil(num));
// Rounding up the first decimal
// 3.1 = 4, -1.1 = 1
console.log("Round ", Math.round(num));
// Rounding up or down depends on the first decimal's place
// Internet Explorer may not supported
// 3.1 = 3, 3.6 = 4, -1.1 = -1
console.log("Trunc ", Math.trunc(num));
// Return random int between 0 and 1
console.log(Math.random())
// Return maximum number
Math.max(10, 13, 25)
// Return mininum number
Math.min(25, 0.5, -45)
console.log("Max ", Math.max(3, 5, -10, 0, 1)); // 5
console.log("Min ", Math.min(1, 2)); // 1
// Return pow(x, y) x powered y times
console.log("Power ", Math.pow(2, 8))
// 2 ** 10 = 1024
console.log(Math.pow(2, 10));
Comments