简单数据类型
1.Number
Number是js三大包装对象之一,数据可直接使用Number对象的属性和方法
下面是Number的部分属性
(1)Number.MAX_VALUE
表示的最大正数。
console.log(Number.MAX_VALUE);//1.7976931348623157e+308
(2)Number.MIN_VALUE
可表示的最小正数-即最接近零的正数(实际上不是零)
console.log(Number.MIN_VALUE);//5e-324
(3) Number.NEGATIVE_INFINITY
表示负无穷大的特殊值;溢出返回
console.log(Number.NEGATIVE_INFINITY);//-Infinity
(4)Number.POSITIVE_INFINITY
表示无穷大的特殊值;溢出返回
console.log(Number.POSITIVE_INFINITY); //Infinity
(5)Number.NaN
特殊的“非数字”值
console.log(Number.NaN);//NaN
2.String
JavaScript中的 String 对象用来表示和操作字符序列。字符串对于保存可以以文本形式表示的数据。并且有一些常用的字符串方法,用来查看字符串的长度,用来寻找字符串的位置等。
(1)不管是'',还是"",在js中都会原样输出
let str = "wode"
let str1 ='wode'
console.log(str);//wode
console.log(str1);//wode
(2)数字与字符串相加,数字在前,字符串在后
console.log(8 + 9 + 1 + 5 + '6'); //236
数字在中间,字符串在两边
console.log(8 + 9 + '1' + 5 + 6); //17156
数字在后,字符串在前
console.log('8' + 9 + 1 + 5); //8915
(3)length属性
length属性可以表示字符串中字符的个数
let str = "wode";
console.log(str.length); //4
3.Boolean
JavaScript Boolean 对象是 JavaScript 中用于表示逻辑值 true 或 false 的对象。它的作用非常简单,就是用于进行逻辑判断和条件语句的控制。
布尔值在与数字或字符串相加时,会强制类型转化为相应的类型
console.log(true+1);//2
console.log(true+'5');//true5
4.Null和Undefined
Null特指对象的值未设置,它是 js基本类型 之一,在布尔运算中被认为是false。
undefined 一般不参与数学运算,参与结果全是NaN。
console.log(null+6);//6
console.log(undefined+6);//NaN
5.检测数据类型的方式
typeof 用于检测数据类型 ,并返回基本数据类型
js的语法规定:undefined返回undefined,null返回object,NaN返回Number。
1.typeof检测数据类型
let b=10;
console.log(typeof b);//number
2.两个typeof检测结果为string
let b=10;
console.log(typeof typeof b);//string
3.undefined,null,NaN的检测
console.log( typeof undefined);//undefined
console.log( typeof NaN);//number
console.log( typeof null);//object
复杂数据类型
复杂数据类型又叫引用类型,具体有数组,函数,正则表达式,日期对象等。