JS笔记4:toString&Date()&Math等

2022-05-05  本文已影响0人  _百草_

1. toString

实例

2. getTime()

Date.getTime() # 返回距 1970 年 1 月 1 日之间的毫秒数:

var d = new Date();
var n = d.getTime()  # 1651730489291,当前时间戳

3. Math.round()

Math.round(x) # 返回一个数字四舍五入后最接近的整数

练习

4. Math.random()

Math.random() # 返回一个浮点数,范围在0-1之间

练习

5. typeof

typeof 变量获取变量的数据类型

typeof null  # 'object' ;空对象
typeof w;  # 'undefined',没有定义值的变量
typeof 1  # 'number'
typeof 1.5  # 'number'
typeof "123"  # 'string'
typeof false;  # 'boolean'
typeof []   # 'object'
typeof {a:1}  # 'object'

参考

  1. Math.round()
  2. Math.random()
  3. 菜鸟教程
  4. JavaScript typeof, null, 和 undefined
上一篇 下一篇

猜你喜欢

热点阅读