15.数据类型判断.html 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. </head>
  8. <body>
  9. <!--
  10. js数据类型
  11. 基本数据类型:
  12. null undefined string boolean number
  13. 引用数据类型
  14. object(object/array/function)
  15. -->
  16. <script>
  17. let obj = {
  18. name:'小明'
  19. }
  20. let arr = [1,2,3];
  21. function fn1() {
  22. return '你好'
  23. }
  24. // 1.typeof
  25. console.log(typeof arr)
  26. // 2.instanceof
  27. console.log(fn1 instanceof Function)
  28. // 3.Object.prototype.toString.call
  29. console.log(Object.prototype.toString.call(fn1));
  30. // 4.constructor
  31. console.log(false.constructor === Boolean)
  32. console.log(fn1.constructor === Boolean)
  33. // console.log(null.constructor === Null)
  34. // console.log(undefined.constructor === Undefined)
  35. </script>
  36. </body>
  37. </html>