<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>JS基础——数据类型</title>
<script>
var i = 100;
//alert(typeof i); //number
var s = 'bokebi';
//alert(typeof s); //string
//alert(s.length); //字符串的长度是6
//alert(s.charAt(3)); //e 类似index,默认从0开始计数
var b = true;
//alert(typeof b); //boolean 布尔值:true / false
var fn = function(){ alert(1); };
//fn(); //1 函数调用
//alert(typeof fn); //function 函数
var obj = document;
//alert(typeof obj); //obj 对象
//obj.abc = 123;
//obj.fn1 = function(){ alert(456) };
//alert(document.abc); //123
//obj.fn1(); //456
var arr = [1,2,3,4,5];
//alert(typeof arr); //obj 对象
//alert(arr.length); //5
//arr[2] = 33; //将数组的第二个元素3替换成33
//alert(arr);
//arr.push(7,8,9); //数组元素后面添加7、8、9
//alert(arr);
var json = { name:'bokebi', age:3 };
//alert(typeof json); //obj 对象
//alert(json.name + '今年' + json.age + '岁了!');
var n = null;
//alert(typeof n); //obj 对象
var u;
alert(typeof u); //undefined 未定义
</script>
</head>
<body>
</body>
</html>
JS中的数据类型:数字、字符串、布尔、函数、对象(obj、[]、{}、null)、未定义
判断数据类型用typeof