<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>判断类型</title>
</head>
<body>
<script>
function getType(obj) {
return Object.prototype.toString.call(obj).slice(8, -1);
}
getType({}) // "Object"
getType(1) // "Number"
getType("hello") // "String"
getType(true) // "Boolean"
getType(null) // "Null"
getType(undefined) // "Undefined"
getType([]) // "Array"
getType(function(){}) // "Function"
</script>
</body>
</html>