What does [object Object] mean?

后端 未结 10 2035
醉酒成梦
醉酒成梦 2020-11-22 03:22

I am trying to alert a returned value from a function and I get this in the alert:

[object Object]  

Here is the JavaScript code:



        
10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-22 04:29

    [object Object] is the default string representation of a JavaScript Object. It is what you'll get if you run this code:

    alert({}); // [object Object]
    

    You can change the default representation by overriding the toString method like so:

    var o = {toString: function(){ return "foo" }};
    alert(o); // foo
    

提交回复
热议问题