What Does [Object Object] Mean? (Javascript)

What does [object Object] mean?

The default conversion from an object to string is "[object Object]".

As you are dealing with jQuery objects, you might want to do

alert(whichIsVisible()[0].id);

to print the element's ID.

As mentioned in the comments, you should use the tools included in browsers like Firefox or Chrome to introspect objects by doing console.log(whichIsVisible()) instead of alert.

Sidenote: IDs should not start with digits.

What does [object Object] mean? (JavaScript)

It means you are alerting an instance of an object. When alerting the object, toString() is called on the object, and the default implementation returns [object Object].

var objA = {};
var objB = new Object;
var objC = {};

objC.toString = function () { return "objC" };

alert(objA); // [object Object]
alert(objB); // [object Object]
alert(objC); // objC

If you want to inspect the object, you should either console.log it, JSON.stringify() it, or enumerate over it's properties and inspect them individually using for in.

Why does this log [object Object], [object Object]?

This is because there is type coercion in your expression. Try to output this: console.log('Contacts: ${JSON.stringify(this.state.contacts)}'); so your object wont be called by ToString but rather JSON.stringify will work first.

what does object || {} means in javascript?

parent.auth || {} means if parent.auth is undefined, null or false in boolean case then new empty object will be initialized and assigned.

or you can understand it like:

var auth;
if(parent.auth){
auth=parent.auth;
} else {
auth={};
}


Related Topics



Leave a reply



Submit