0

Running a code like that results in inconsistent logging:

const d = document.createElement('div');
console.log(d);
setTimeout(() => {
  const d = document.createElement('div');
  console.log(d);
});

Result:

screenshot of the result

As you can see, the first one is printed as an object, and the second one is printed as an HTML element.

Related question - Always reveal html element in console.log (Chromium)

Konrad
  • 21,590
  • 4
  • 28
  • 64
  • Inconsistent with what? – Pointy Aug 16 '22 at 19:31
  • They look exactly the same in the snippet here. The console API is basically what the browser decides to give you, there's no standard and in particular it is definitely not part of the language spec. – Pointy Aug 16 '22 at 19:33
  • 1
    https://stackoverflow.com/questions/71034045/google-chromes-console-log-prints-dom-nodes-inconsistently – epascarello Aug 16 '22 at 19:34
  • 1
    @Pointy, logs still appear in the dev tools when you are a snippet. I included the picture to show the difference. I never said that I'm asking about language specification. I directly asked about google chrome. – Konrad Aug 16 '22 at 19:54
  • 1
    And the console API actually has its own specs: https://console.spec.whatwg.org (though the actual "printer operation" is still "implementation-defined".) – Kaiido Aug 16 '22 at 23:09

0 Answers0