0

Trying to get a single object returned by request using callbacks. Callback

Error:undefined Data:[object Object] Why are there two objects being returned when I am returning only one error and one object?

5
  • 2
    Instead of undefined, please send null. Commented Apr 30, 2020 at 3:09
  • @MihirKumar Sending a error as null when there is no error.Callback prints null. But I am not getting the object. Error:null Data:[object Object] Didn't get it. Can you please elaborate Commented Apr 30, 2020 at 3:14
  • Instead of null everywhere you need to use null & JSON.stringify the data you are sending and then JSON.parse it again in geoCode Commented Apr 30, 2020 at 3:57
  • 1
    Please post code as text, not as images. When you post it as an image, it won't be indexed for search, people trying to write answers can't copy your code into an answer and fix/modify it and its much harder to deal with on mobile devices. Please post code as text. Commented Apr 30, 2020 at 4:08
  • I tried formatting,there were too many indentation errors. I moved a few spaces and the code was not readable. Commented Apr 30, 2020 at 4:12

1 Answer 1

1

Actually, there is only one object being returned from the callback. The reason why [object Object] is printed, is because that is the default serialization of an object.

You can see this answer for a detailed explanation:
what does [object Object] mean?

To print the data contained in the object, you can JSON.stringify it like this:

    console.log("Data:"+JSON.stringify(data))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.