来源于技术胖的视频总
1.验证是否是数字Number.isFinite(2.444)
,只要是数字,不管是整型还是浮点型,都会返回true
let num = 2.333
let num2 = 2
let num3 = '3'
let str = 'yian'
console.log(Number.isFinite(num))//true
console.log(Number.isFinite(num2))//true
console.log(Number.isFinite(num3))//false
console.log(Number.isFinite(str))//false
2.验证是否为整数Number.isInteger(num)
,是返回true
let num=22
let num2=22.33
console.log(Number.isInteger(num))//true
console.log(Number.isInteger(num2))//false
3.验证是否是NAN
(NAN
表示非数字)
console.log(Number.isNaN(NaN))//true
4.整数转换parseInt()
和浮点型转换parseFloat()
let a='2.66'
console.log(parseInt(a))//2
console.log(parseFloat(a))//2.66
5.整数的取值范围2^53
let num=Math.pow(2,53)-1
console.log(num)//9007199254740991
6.最大安全整数Number.MAX_SAFE_INTEGER
console.log(Number.MAX_SAFE_INTEGER)//9007199254740991
7.最小安全整数Number.MIN_SAFE_INTEGER
console.log(Number.MIN_SAFE_INTEGER)//-9007199254740991
8.安全整数的判断isSafeInteger(num)
let num = Math.pow(2,53)
console.log(Number.isSafeInteger(num))//false