一、什么是内置对象
1.js的三种对象
- 普通对象
- 内置对象
- 浏览器对象
2.什么是内置对象
- js内置对象就是js本身封装好了的对象,可以直接使用的对象。
3.常见的js内置对象总结
(1)求最大值最小值
- Math.max()
- Math.min()
(2)三个取整的方法
- Math.floor() ---- 向下取整
- Math.ceil() ---- 向上取整
- Math.round() ---- 四舍五入
(3)比较重要的一个方法
- Math.random ---- 0-1之间的随机数
4.代码实现
<!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>
// (1)求最大值最小值
// Math.max
console.log(Math.max(1,2,3,4));
// Math.min()
console.log(Math.min(1,2,3,4));
// (2)三个取整的方法
// Math.floor()----向下取整
console.log(Math.floor(1.1));
// Math.ceil()----向上取整
console.log(Math.ceil(1.1));
// Math.round()----四舍五入
console.log(Math.round(1.5));
// (3)比较重要的一个方法
// Math.random----0 - 1之间的随机数
console.log(Math.random());
</script>
</body>
</html>
实现结果: