Hey.

  1. I do not understand why this is displayed differently in the console with different recording options: enter image description here

  2. Here is a second example: enter image description here

I don’t understand why, if “recording” something simply by itself in the console, it is displayed IN ONE, and if it is to push this “cons” into the function, then it will be displayed OTHER THAN?

  • four
    because this is how the console works. - Grundy
  • How does this "console work"? what is the difference between these two records? I asked why, and answered "because it works that way") - Dimon
  • one
    The first one displays the value of the expression. in the second, the output is regulated by the log function. In general, what and how should the console display is not specified anywhere, so the results can vary greatly in different browsers. If the chrome console is of particular interest - you should go to the source and see what happens in one or another case. - Grundy

2 answers 2

By assigning a variable to a value or expression that returns it, and then returning it by the name of the variable, we get the value of the variable or the expression that should return this value after the call. If we try to read the value using the console.log() command, we will get

HTML-like tree

so it is called on the website MDN, in the same place they write that console.dir() returns

JSON-like tree

Maybe I didn’t answer the question, and in principle it’s better to ask on the developers' forums of each browser individually, but now I hope something cleared up, well, at least where to dig further).

  • Thanks for the reply - Dimon

The console displays the result of the last calculation. The console.log function is not standardized, but at the moment, according to the description on MDN, it displays its HTML representation for the transferred DOM element and its JSON representation for the transferred object.