Skip to content

Commit 509a676

Browse files
committed
Doc improvements
1 parent ce9caa2 commit 509a676

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

doc/api/stdio.markdown

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,30 @@ Prints to stdout with newline. This function can take multiple arguments in a
99

1010
console.log('count: %d', count);
1111

12-
If formating elements are not found in the first string then `util.inspect`
13-
is used on each argument.
12+
The first argument is a string that contains zero or more *placeholders*.
13+
Each placeholder is replaced with the converted value from its corresponding
14+
argument. Supported placeholders are:
15+
16+
* `%s` - String.
17+
* `%d` - Number (both integer and float).
18+
* `%j` - JSON.
19+
20+
If the placeholder does not have a corresponding argument, `undefined` is used.
21+
22+
console.log('%s:%s', 'foo'); // 'foo:undefined'
23+
24+
If there are more arguments than placeholders, the extra arguments are
25+
converted to strings with `util.inspect()` and these strings are concatenated,
26+
delimited by a space.
27+
28+
console.log('%s:%s', 'foo', 'bar', 'baz'); // 'foo:bar baz'
29+
30+
If the first argument is not a format string then `console.log()` prints
31+
a string that is the concatenation of all its arguments separated by spaces.
32+
Each argument is converted to a string with `util.inspect()`.
33+
34+
console.log(1, 2, 3); // '1 2 3'
35+
1436

1537
### console.info()
1638

0 commit comments

Comments
 (0)