1.Math对象用于执行数学任务 。
2.PI 属性用于返回圆周率
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 返回圆周率
console.log(Math.PI);
</script>
</body>
</html>
3.abs(x) 返回 x 的绝对值。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// abs(x) 返回 x 的绝对值。
console.log(Math.abs(100));
console.log(Math.abs(-100));
</script>
</body>
</html>
3.ceil(x) 对 x 数进行上舍入,向上取整。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// ceil(x) 对 x 数进行上舍入,向上取整。
console.log(Math.ceil(55.99999));
console.log(Math.ceil(55.00001));
</script>
</body>
</html>
4.floor(x) 对 x 数进行下舍入,向下取整。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// floor(x) 对 x 数进行下舍入,向下取整。
console.log(Math.floor(55.99999));
console.log(Math.floor(55.00001));
</script>
</body>
</html>
5.max(x,y,z,...,n) 返回 x,y,z,...,n 中的最高值
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// max(x,y,z,...,n) 返回 x,y,z,...,n 中的最高值
console.log(Math.max(11,22,333,44,55));
</script>
</body>
</html>
6. min(x,y,z,...,n) 返回 x,y,z,...,n中的最低值
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// min(x,y,z,...,n) 返回 x,y,z,...,n 中的最低值
console.log(Math.min(11,22,333,44,55));
</script>
</body>
</html>
7.pow(x,y) 返回 x 的 y 次方
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// pow(x,y) 返回 x 的 y 次方
console.log(Math.pow(3,3));
console.log(Math.pow(4,4));
</script>
</body>
</html>
8.random() 返回 0 ~ 1 之间的随机数。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// random() 返回 0 ~ 1 之间的随机数
console.log(Math.random());
// 返回一个2000到8000之间的随机数
console.log(Math.floor(Math.random()*6000)+2000);
</script>
</body>
</html>
9.round(x) 四舍五入。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
console.log(Math.round(55.5));
console.log(Math.round(55.4));
</script>
</body>
</html>
10.sqrt(x) 返回数的平方根。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// sqrt(x) 返回数的平方根
console.log(Math.sqrt(9));
console.log(Math.sqrt(16));
console.log(Math.sqrt(33));
</script>
</body>
</html>