js判断一个变量是不是对象
时间: 2023-09-03 14:25:41
浏览: 161
### 回答1:
可以使用 `typeof` 运算符来[判断]([http]([http](https://geek.csdn.net/educolumn/68f28ca3131d47699e5902c5d3d74d51?spm=1055.2569.3001.10083)s://geek.csdn.net/educolumn/68f28ca3131d47699e5902c5d3d74d51?spm=1055.2569.3001.10083)s://geek.csdn.net/educolumn/598ee2e4d0090de966a6f73039c4643b?spm=1055.2569.3001.10083)变量的[类型](https://geek.csdn.net/educolumn/2f8e8df4d4a5ce5581ebfcbeb16e1298?spm=1055.2569.3001.10083)。如果变量是[对象](https://geek.csdn.net/educolumn/04c51611e4b730957464192e0307b82c?spm=1055.2569.3001.10083),则 `typeof` 运算符会返回 "object"。
let obj = {};
if (typeof obj === "object") {
console.log("obj is an object");
```