<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script>
var a=1;
var b=2.1;
var c=true;
var d="";
function isInteger(num) {
if (!isNaN(num) && num % 1 === 0) {
document.write('a是一個整型'+'</br>');
} else {
document.write('a不是一個整型'+'</br>');
}
} //封裝函數
isInteger(a); //調用執行
function isFloat(num) {
if (!isNaN(num) && num % 1 !== 0) {
document.write('b是一個浮點型'+'</br>');
} else {
document.write('b不是一個浮點型'+'</br>');
}
}
isFloat(b);
document.write ('c的數據類型為'+typeof c,'</br>'+'d的數據類型為'+typeof d);
</script>
</body>
</html>