-3

why i get this [object Object] and not just "object" i.e. just its type?

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>
  • 1
    Is this even a question? The content of your question makes no sense. Are you asking or telling? – Snowmonkey Apr 06 '17 at 18:51
  • @Snowmonkey It was unformatted code. Of course, still not really a question. – Sebastian Simon Apr 06 '17 at 18:52
  • 1
    So, once again, what exactly is the bug/glitch/question? – Snowmonkey Apr 06 '17 at 18:53
  • Possible duplicate of [How can I display a JavaScript object?](http://stackoverflow.com/questions/957537/how-can-i-display-a-javascript-object) – Sebastian Simon Apr 06 '17 at 18:54
  • Also a dupe of [What does `[object Object]` mean?](http://stackoverflow.com/q/4750225/4642212) or [Why `[object Object]` mentions “object” twice?](http://stackoverflow.com/q/29847665/4642212), depending on what the actual question is. Why did you expect anything else, let alone the type? – Sebastian Simon Apr 06 '17 at 18:54
  • 3
    Possible duplicate of [what does \[object Object\] mean?](http://stackoverflow.com/questions/4750225/what-does-object-object-mean) – Joseph Beard Apr 06 '17 at 18:56
  • I have edited it .. you can see the it now. – Mohamed Bahgat Apr 06 '17 at 19:01
  • run the javascript portion of that directly in your console, you'll see that what you actually get is Object {firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue"} – Snowmonkey Apr 06 '17 at 19:14

1 Answers1

1

Because you are concatenating person with "<br />". In that process, person is converted to a string. The default string representation of an object is [object Object].

If you wrote

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

instead, then you'd only get object.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143