💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
```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> ```