You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
👆 this isn't precisely spec compliant. Why? Because there's supposed to be this:
which means something more like this:
assert(expression, ...args){if(!expression){if(typeofargs[0]==="string"){// if you provide a fmt string, it still gets used (first arg)args[0]=`Assertion failed: ${args[0]}`}else{// but if it's anything else, it's not stringified as a format string;// its just an object to be printed. so we prepend a fmt string arg (with no specifiers// that would eat any user-supplied objects) as a nice "Assertion failed" messageArrayPrototypeUnshift(args,"Assertion failed")}// The arguments will be formatted in warn() againReflectApply(this.warn,this,args);}},
you can see a bug here from the current Node.js impl that highlights what's happening:
constmySymbol=Symbol()console.assert(false,mySymbol)// THROWS because Symbol() cant be stringified like `symbol string: ${Symbol()}`!
the mdn thing you cited:
A list of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed and output.
also backed up by someone from the whatwg/console repo:
My understanding of the spec is the object {hello: "world"} would get passed as a member of args (eg, ["Assertion failed", {hello: "world"}]) to Printer, which is implementation defined. Converting a POJO to the string "[object Object]" is certainly a valid way of being implementation defined, but I wouldn't judge it "to be maximally useful and informative."
@bnoordhuis I believe it's fine to handle it that way. It aligns well with the other APIs where the object would be printed in a human readable way. There's also already an open PR and I guess we could reopen the issue as such?
Activity
bnoordhuis commentedon Sep 17, 2023
Working as expected/documented. Try this instead:
It wouldn't be hard to use
util.inspect()by default but:You're welcome to open a pull request and see how it's received if you still think it's a good idea but be prepared for rejection.
jcbhmr commentedon Sep 17, 2023
bnoordhuis commentedon Sep 17, 2023
Yes, I'm pretty sure. The more human-readable prose from the MDN lemma (emphasis mine):
It's only when you use a message format string that object formatting comes into play:
jcbhmr commentedon Sep 19, 2023
After further investigation, here's the erroneous line:
node/lib/internal/console/constructor.js
Line 435 in cd97e28
👆 this isn't precisely spec compliant. Why? Because there's supposed to be this:

which means something more like this:
you can see a bug here from the current Node.js impl that highlights what's happening:
the mdn thing you cited:
this same language "string representations" is also used in console.info() and other console methods to mean the formatted pretty output not the

.toString()version:https://developer.mozilla.org/en-US/docs/Web/API/console/info
also backed up by someone from the whatwg/console repo:
whatwg/console#226 (comment)
so in summary it would seem:
[object Object]is a valid string representation of the objectSymbol()not being stringifiable in the wayconsole.assert()is implementedconsole.assert(false, {a:1})is properly inspected; Node.js is the outlier.i also am making an effort to clarify the mdn wording that had us all confused 🤣 mdn/content#29172
[-]`console.assert(false, { hello: "world" })` logs `[object Object]` instead of inspecting the object[/-][+]`console.assert(false, Symbol())` throws[/+]jcbhmr commentedon Sep 19, 2023
Changed title and body to reflect exact buggy impl:
console: treat non-strings as separate argument in console.assert()
BridgeAR commentedon Sep 19, 2023
@bnoordhuis I believe it's fine to handle it that way. It aligns well with the other APIs where the object would be printed in a human readable way. There's also already an open PR and I guess we could reopen the issue as such?
bnoordhuis commentedon Sep 20, 2023
Yeah, I'm fine with that, I don't really have a strong opinion either way except that changing the default should be a semver-major change.
console: treat non-strings as separate argument in console.assert()