在JS中一共有7种数据类型,包括5种基本数据类型和2种复杂数据类型
五种基本数据类型
* string(字符型)
* number(数值型)
* boolean(布尔型)
* undefined(未定义型)
* null(空型)
在这里先简单说下undefined和null的区别
undefined:未定义,如果一个变量只声明但是未赋值,默认值就是undefined
<script>
function count() {
var a;
console.log ( a );//undefined 变量的值
}
</script>
<button type="button" onclick="count()">确定吗</button>
运行结果如下null:空值 //null这个值只能手动去设置,一个变量在任何情况下它的值都不会主动是null
var b = null;
console.log ( b );//null