🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <pre style="font-size:16px; font-weight:700"> 判断变量是哪种数据类型有三种方式:typeof、instanceof、Object.prototype.toString.call,其中建议使用instanceof。 </pre> <body> <script type="text/javascript"> var str = "字符串对象"; console.log(typeof str); // String function Person(name, age) { this.name = name; this.age = age; } var p = new Person("小明", 21); console.log(p instanceof Person); // true var uf; var nu = null; console.log(Object.prototype.toString.call(uf)); // Undefined console.log(Object.prototype.toString.call(nu)); // Null console.log(Object.prototype.toString.call(p)); // Object </script> </body> </html> ```