Skip to content

Commit

Permalink
doc, util, console: clarify ambiguous docs
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
nattelog authored and MylesBorins committed Aug 16, 2017
1 parent c5c65c8 commit 7f6f1c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,7 @@ console.log('count:', count);
// Prints: count: 5, to stdout
```

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

### console.time(label)
<!-- YAML
Expand Down
11 changes: 6 additions & 5 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,17 @@ util.format('%s:%s', 'foo');
// Returns: 'foo:%s'
```

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

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

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

Expand Down

0 comments on commit 7f6f1c2

Please sign in to comment.