显示所有变量的类型

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h2>JavaScript typeof 运算符</h2>
  6.  
  7. <p>typeof 运算符返回变量、对象、函数或表达式的类型。</p>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. document.getElementById("demo").innerHTML =
  13. typeof "john" + "<br>" +
  14. typeof 3.14 + "<br>" +
  15. typeof NaN + "<br>" +
  16. typeof false + "<br>" +
  17. typeof [1,2,3,4] + "<br>" +
  18. typeof {name:'john', age:34} + "<br>" +
  19. typeof new Date() + "<br>" +
  20. typeof function () {} + "<br>" +
  21. typeof myCar + "<br>" +
  22. typeof null;
  23. </script>
  24.  
  25. </body>
  26. </html>