Skip to content

Commit 7f6f1c2

Browse files
nattelogMylesBorins
authored andcommitted
doc, util, console: clarify ambiguous docs
Add clarification to the documentation on util.format() and console.log() regarding how excessive arguments are treated when the first argument is a non-format string compared to when it is not a string at all. PR-URL: #14027 Fixes: #13908 Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent c5c65c8 commit 7f6f1c2

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

doc/api/console.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,7 @@ console.log('count:', count);
227227
// Prints: count: 5, to stdout
228228
```
229229

230-
If formatting elements (e.g. `%d`) are not found in the first string then
231-
[`util.inspect()`][] is called on each argument and the resulting string
232-
values are concatenated. See [`util.format()`][] for more information.
230+
See [`util.format()`][] for more information.
233231

234232
### console.time(label)
235233
<!-- YAML

doc/api/util.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,17 @@ util.format('%s:%s', 'foo');
116116
// Returns: 'foo:%s'
117117
```
118118

119-
If there are more arguments passed to the `util.format()` method than the
120-
number of placeholders, the extra arguments are coerced into strings (for
121-
objects and symbols, `util.inspect()` is used) then concatenated to the
122-
returned string, each delimited by a space.
119+
If there are more arguments passed to the `util.format()` method than the number
120+
of placeholders, the extra arguments are coerced into strings then concatenated
121+
to the returned string, each delimited by a space. Excessive arguments whose
122+
`typeof` is `'object'` or `'symbol'` (except `null`) will be transformed by
123+
`util.inspect()`.
123124

124125
```js
125126
util.format('%s:%s', 'foo', 'bar', 'baz'); // 'foo:bar baz'
126127
```
127128

128-
If the first argument is not a format string then `util.format()` returns
129+
If the first argument is not a string then `util.format()` returns
129130
a string that is the concatenation of all arguments separated by spaces.
130131
Each argument is converted to a string using `util.inspect()`.
131132

0 commit comments

Comments
 (0)