Repository navigation
Clarify wording around "string representation" in console.* related functions #29172
Description
Activity
- addedneeds triageTriage needed by staff and/or partners. Automatically applied when an issue is opened.Triage needed by staff and/or partners. Automatically applied when an issue is opened.
on Sep 17, 2023 - addedContent:WebAPIWeb API docsWeb API docsand removedContent:WebAPIWeb API docsWeb API docs
on Sep 17, 2023 - changed the title
[-]`console.assert(condition, ...data)` -- are `...data` elements coerced to a string or not?[/-][+]What should `console.assert(condition, { a: 1 })` show in the console?[/+]on Sep 17, 2023 - changed the title
[-]What should `console.assert(condition, { a: 1 })` show in the console?[/-][+]What should `console.assert(false, { a: 1 })` show in the console?[/+]on Sep 17, 2023 2 Let message be a string without any formatting specifiers indicating generically an assertion failure (such as "Assertion failed").
4.2 If Type(first) is not String, then prepend message to data.
As per the specs data objects are to be appended to a string (message). So the NodeJS's output
Assertion failed: [object Object]is correct as per the specs.const obj = {a:1}; const message = "Assertion failed: " + obj; // Assertion failed: [object Object]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
console.assert(false, JSON.strigify(obj)).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.
Reacted by Jacob Hummer- addedContent:WebAPIWeb API docsWeb API docsneeds infoNeeds more information to review or act on.Needs more information to review or act on.and removedneeds triageTriage needed by staff and/or partners. Automatically applied when an issue is opened.Triage needed by staff and/or partners. Automatically applied when an issue is opened.
on Sep 18, 2023 - changed the title
[-]What should `console.assert(false, { a: 1 })` show in the console?[/-][+]Clarify wording around "string representation" in console.* related functions[/+]on Sep 19, 2023 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.
- addedhelp wantedIf you know something about this topic, we would love your help!If you know something about this topic, we would love your help!and removedneeds infoNeeds more information to review or act on.Needs more information to review or act on.
on Sep 19, 2023
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