-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify wording around "string representation" in console.* related functions #29172
Comments
console.assert(condition, ...data)
-- are ...data
elements coerced to a string or not?console.assert(condition, { a: 1 })
show in the console?
console.assert(condition, { a: 1 })
show in the console?console.assert(false, { a: 1 })
show in the console?
As per the specs data objects are to be appended to a string (message). So the NodeJS's output
Unlike NodeJs, browsers can show interactable objects in the logs. Because the console logs are part of the developer tools in browsers, it is a good feature to show the objects like that. It saves us from doing |
This comment was marked as outdated.
This comment was marked as outdated.
Note that console spec is not a strict spec, per se—it's an attempt to find the greatest common divisor of all existing implementations. Therefore a lot of things are left very ambiguous, and so is the documentation... I'm inclined to say this is a divergence allowed in spec, whether the second arg should be a format string or a value to be directly printed. |
console.assert(false, { a: 1 })
show in the console?
I got my answer about "which is correct" from the whatwg/console folks: whatwg/console#226 (comment) I've switched this issue title/text to be focused on improving the wording about "string representation concatenated together" which is more on-topic as far as MDN content is concerned. 👍 let me know your thoughts! ❤ |
I think the console docs in general would benefit from some analysis of how the input is interpreted and printed, but I don't think anyone is getting to it soon. |
old text
MDN URL
https://developer.mozilla.org/en-US/docs/Web/API/console/assert
What specific section or headline is this issue about?
The part about passing in objects
What information was incorrect, unhelpful, or incomplete?
What should this print?
In the spec text https://console.spec.whatwg.org/#assert it would seem (from my limited understanding) that it should forward everything to
Logger()
and it should printAssertion failed ▶ { a: 1 }
like most other console methods do. That's what Chrome and Firefox do at least....but then on MDN there's this text: https://developer.mozilla.org/en-US/docs/Web/API/console/assert
which reads (to me at least; i could be mistaken) that passing
console.assert(false, {a:1},{b:2})
will doString()
or similar on each of those{a:1}
objects...which would seem to indicate that Node.js has the right idea:
idk man, I'm just a bit confused which one is "right" 😂
What did you expect to see?
Rephrase the text to be a bit more clear on whether "The string representations of each of these objects are appended together in the order listed and output." means perform string coercion or print a fancy object repr.
or idk maybe a little note or some screenshots of what happens sorta like https://developer.mozilla.org/en-US/docs/Web/API/console#using_groups_in_the_console which has a very nice image
or maybe a little note about how Node.js has a slightly different way of doing it 🤷♂️
Do you have any supporting links, references, or citations?
https://console.spec.whatwg.org/#assert
nodejs/node#49680
whatwg/console#77
Do you have anything more you want to share?
No response
Right now in a lot of the console.* methods there's this type of language used:
This is potentially confusing. It seems to indicate that said objects will all be
.toString()
-ed and concatenated together, sorta like this:but that's obviously NOT what it means to convey. Instead, it means to convey that these objects are "inspected" or "pretty printed" and then "shown" (not necessarily "printed") to the console in the specified order.
The issue at hand: Should this change?
If so, here's an idea:
obj1 … objN
A list of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed and output.
obj1 … objN
A list of non-string values to inspect in the console. The method of inspection is implementation defined. Browser consoles have interactive consoles, while text-based output may pretty-print the objects.
idk tho. something more clear like that
affected pages that i could find:
console.trace() has a pretty decent description https://developer.mozilla.org/en-US/docs/Web/API/console/trace
The text was updated successfully, but these errors were encountered: