JS数据类型Undefined、Number

221 阅读1分钟

Undefined:

未定义,或者是定义了变量但是却没有初始化赋值

Number:

数字

  • 保留小数后两位——toFixed(2);
  • 保留小数后n位但是不要无效的0——toFixed(n)/100*100;
  • 小数向上取整数——Math.ceil()
  • 小数向下取整数——Math.floor()
  • 小数四舍五入取整——Math.round()

image.png

image.png

image.png

image.png

  • 拓展:
    • Math函数:ceil、floor、round、max、min、random、PI
    • ==(相等操作符):只比较两边的值(引用数据会比较是否在同一个内存空间)
    • ===(全等操作符):不仅比较两边的值,而且比较两边的类型
  • 注意:JS不能用于科研运算,可以用作一般互联网产品,因为运算有精度

image.png

image.png