Skip to content

Commit d4a6ca6

Browse files
nattelogaddaleax
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 e71b98f commit d4a6ca6

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
@@ -246,9 +246,7 @@ console.log('count:', count);
246246
// Prints: count: 5, to stdout
247247
```
248248

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

253251
### console.time(label)
254252
<!-- YAML

doc/api/util.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,17 @@ util.format('%s:%s', 'foo');
177177
// Returns: 'foo:%s'
178178
```
179179

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

185186
```js
186187
util.format('%s:%s', 'foo', 'bar', 'baz'); // 'foo:bar baz'
187188
```
188189

189-
If the first argument is not a format string then `util.format()` returns
190+
If the first argument is not a string then `util.format()` returns
190191
a string that is the concatenation of all arguments separated by spaces.
191192
Each argument is converted to a string using `util.inspect()`.
192193

0 commit comments

Comments
 (0)