【问题标题】:Why do I get this [object Object] and not just "object" i.e. just its type?为什么我得到这个 [object Object] 而不仅仅是“object”,即它的类型?
【发布时间】:2017-04-06 18:49:20
【问题描述】:

为什么我得到这个 [object Object] 而不仅仅是“object”,即它的类型?

var person = {
  firstName: "John",
  lastName: "Doe",
  age: 50,
  eyeColor: "blue"
};
var person;
document.getElementById("demo").innerHTML = person + "<br>" + typeof person;
<p>Variables can be emptied by setting the value to <b>undefined</b>.</p>
<p id="demo"></p>

【问题讨论】:

标签: javascript


【解决方案1】:

因为您将person"&lt;br /&gt;" 连接起来。在该过程中,person 被转换为字符串。对象的默认字符串表示形式是[object Object]

如果你写了

document.getElementById("demo").innerHTML = typeof person;

相反,你只会得到object

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 2011-01-12
    • 2021-01-26
    • 2021-04-15
    • 1970-01-01
    • 2019-09-15
    相关资源
    最近更新 更多