Using one call avoids code duplication -> no multiple calls
Using a template literal works, but is sensitive to formatting -> no template literal
I guess browsers pick their own way to delimit arguments, and there is no way to specify the delimiter. It seems to be a space. -> no specify '\n' as delimiter
After considering these solutions, we arrive at what @Vasan has pointed out in a comment - console has powerful printf-style formatting capabilities.
const s1 = "foo";
const s2 = "bar";
const a = { a: 1 };
const b = { b: 2 };
console.info("Remove space delimiter");
console.log("%s%s", s1, s2);
console.info("Separate with newline");
console.log("%s\n%s", s1, s2);
// Interactive object and label
// See https://developer.mozilla.org/en-US/docs/Web/API/console/log#logging_objects
console.info("Interactive object and label");
console.log(
"%s\n%o",
"`a` object",
a,
);
// Object snapshot and label
// See https://developer.mozilla.org/en-US/docs/Web/API/console/log#logging_objects
console.info("Object snapshot and label");
console.log(
"%s\n%o",
"`a` object is",
JSON.parse(JSON.stringify(a)),
);
console.info("Multiple objects *");
console.log("%o\n%o", a, b);
* Awkwardly, in Firefox, it seems that objects that are not the first nor last replacement argument have spaces on both sides no matter what. This does not seem to be the case in Chrome.
See console and particularly console string substitutions.
Aside
console output can even be styled using some CSS properties.
See https://gitlab.com/users/sign_in for an example of this.
See https://developer.mozilla.org/en-US/docs/Web/API/console#styling_console_output
console.log(a); console.log(b); console.log(c)works as well