[读码时间] 用typeof查看数据类型
说明:代码取自网络,注释为笔者学习时添加!
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>用typeof查看数据类型</title> <style> pre { color: green; padding: 10px 15px; background: #f0f0f0;/*灰色*/ border: 1px dotted #333;/*黑色*/ font: 12px/1.5 Courier New;/*行高18px*/ } span { color: #999;/*灰黑色*/ } </style> </head> <body> <pre> <script type="text/javascript"> alert(typeof 12345); <span>//输出number</span> alert(typeof "abc"); <span>//输出string</span> alert(typeof document); <span>//输出object</span> </script> </pre> <script> alert("typeof 12345 → " + typeof 12345 + "\ \n\ntypeof \"abc\" → " + typeof "abc" + "\ \n\ntypeof document → " + typeof document ); </script> </body> </html>