This one came up in a code review and I'm dragging the internet into the argument.
Given that...
Node.js documentation for console.log says that console.log will pass its non-string arguments to util.format.
Node.js documentation for util.format mentions that util.format is intended as a debugging tool.
Node.js documentation for util.inspect says that console.log and util.format call into util.inspect and furthermore claims:
util.inspect(object[, options])The
util.inspect()method returns a string representation ofobjectthat is intended for debugging. The output ofutil.inspectmay change at any time and should not be depended upon programmatically.
(emphasis is mine, and I'm already familiar the answers to Difference between "process.stdout.write" and "console.log" in node.js?)
Does that mean...
Does that mean that it is inappropriate to write the simplest thing like console.log(1) if the output is to be consumed by another process programmatically? ...because the arguments are being passed to util.inspect, which seems to reserve the right to change the format of the output at any time? Any non-string argument, would seem to be a no-no. And "may change at any time" seems to reserve enough freedom that it might start outputting random emojis tomorrow if it feels like it.
Do we get any guarantees at all of what the output from console.log will be when passing a non-string argument?