最近做项目中遇到了一些关于Javascript数据类型的判断处理,上网找了一下资料,并且亲自验证了各种数据类型的判断网页特效,在此做一个总结吧!
1.数值型(Number):包括整数、浮点数。
2.布尔型(Boolean)
3.字符串型(String)
4.对象(Object)
5.数组(Array)
6.空值(Null)
7.未定义(Undefined)
比较常用的判断方法是:
1 function isNumber(val){2 return typeof val === 'number';3 }
但有些情况就不行,比如:
1 var a;2 alert(isNumber(parseInt(a)));
这里弹出来的是true,如下图所示:
phpuM+JeI+4x4u5x3D2OO8dxhx536HG7Dit1WKnDCh1u0+I2LW51xBiWu4WMGhrcYguiRUM0O2KUkNrjFiWaRpzRSMYdovEO0WCPenvUDTvjJhlDxM0hopYSNWQMEtVuUeWIAaJqgJD4HeTyjtXdv7lm0LZdaknIspHlpJbcsTuOHST3l9x3am1Qa8lRdc2jziptsQVu0WCZxuUouB+j1jHKQdTiVq3tyNJCQYaOIZSBRDs19H6FeRYnbYzUNDSqLgn7Lwn784SDecLhPOFIvlCTL9TkC3X5Qn2+0JAvNOULTfkCc77AYo8zf0hL2sEh48wf0hj/Ys4XmPIFpnyhIV+o/0io+0io+Uio+Ug48pFwOF84mC/szxf25wlVeUJNY2PSxsjJe7hzHCOHIBxqGDTjoUlbDNtjKGQxuOAwLzAGzLjfbDOLasKmjD4j7jXgbgPuGsdd47iTNIXergmdUxM+BDHmEASmCkLKKIgRZkE0LFoQ7o6g2oFREGK38CiLAWZZ1CxaFg2eZDHCIaspXRa2aqcdDgZZhNEUygBNYZ7FiZERo7W1vedz+87n9p3PVZ/P7RfkDgpyhwW5I4JcjSBXI8jVCc7oBWcMgjMmwRmT4M9kJO3gzNtJ2sH505tv0f5iEvzZJDhjEJzRC87oBGc0glyNMHdEmDsszB0U5vYLc9WC3D5Bbp8gt1eQO3qzNjEywqYJMn2g2mF4Et+x4DsWPGLBI1Y8YrW9fYBi0hnDgYSLnqi+MGGVI62wy6JzHLfrsZJqikAE0cKUQUg9ZBCMjrBdRcNEvbsghv0VRJUfGYSL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