确定变量的类型

  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p>typeof 运算符返回变量或表达式的类型。</p>
  6.  
  7. <p id="demo"></p>
  8.  
  9. <script>
  10. document.getElementById("demo").innerHTML =
  11. typeof "" + "<br>" +
  12. typeof "Bill" + "<br>" +
  13. typeof "Bill Gates" + "<br>" +
  14. typeof 0 + "<br>" +
  15. typeof 314 + "<br>" +
  16. typeof 3.14 + "<br>" +
  17. typeof (3.14);
  18. </script>
  19. </body>
  20. </html>