Skip to content
Advertisement

What does [object Object] mean? (JavaScript)

One of my alerts is giving the following result:

[object Object] 

What does this mean exactly? (This was an alert of some jQuery object.)

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement