<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS中所有变量的类型</title>
<script>
var a = 12;
// alert(typeof a); // number
a = 'abc';
// alert(typeof a); // String
a = true;
// alert(typeof a); // boolean
a = function(){
}
// alert(typeof a); // function
a = document;
// alert(typeof a); // object
/*
undefined: 有两种情况下, 变量的类型是undefined
1. 变量根本就没有被声明
2. 声明了一个变量, 但是变量并没有初始化赋值
以上的两种情况下, 此变量的类型就会显示undefined
*/
alert(typeof b); // undefined
/*
总结:
在JavaScript中总共提供了六种变量的类型, 分别是:
number, String, boolean, function, object, underfined
*/
</script>
</head>
<body>
</body>
</html>