0

I'm trying to return an object response from a function, but while I was debugging in the Chrome dev tools, I noticed that it had a property that it shouldn't. I removed things from the response until it was eventually just an empty object, followed immediately by a console.log:

const result = {};
console.log(result);

But it still shows up in the Chrome console with the extra property:

{
    layerId: 1
}

When I try console.log(result.layerId), it returns undefined. If I stringify it with console.log(JSON.stringify(result)), it correctly logs {}.

Does anyone know why this might be happening?

Alex
  • 213
  • 2
  • 8
  • impossible to tell from what is provided. Show code that produces the issue. Might be https://stackoverflow.com/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays – epascarello Sep 13 '19 at 19:36
  • I have literally included all of the code. It is a new constant, with a unique name, followed immediately by a console.log. – Alex Sep 13 '19 at 19:45
  • Nothing else should be modifying this result object to inject 'layerId', but I'll be going through to make sure it isn't a shallow copy problem. – Alex Sep 13 '19 at 19:48

2 Answers2

0

I believe result object had been used in the console, still saving constant result. Does it still happen when you try it on new tab/window console?

tlrmacl
  • 51
  • 1
  • I tried a new tab, then restarting the browser along with clearing the cache, and also renaming the constant. Still showing up! – Alex Sep 13 '19 at 19:22
0

Do you have any debugging chrome extensions loaded/running? Some of these attach properties to the console/objects in order for the tool to run. Many different possibilities, so to rule that out, can you disable extensions and see if it persists?

John K
  • 1
  • No need--I have no extensions at all, this is a plain Chrome install on the latest version. 'layerId' is a property I use elsewhere, so I recognize it, but in my test case this is a new constant, with a unique name, that is being logged immediately after creation. – Alex Sep 13 '19 at 19:35