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.

Fixes: nodejs#13908
  • Loading branch information
nattelog committed Jul 1, 2017
1 parent f803e77 commit b687f17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 1 addition & 3 deletions doc/api/console.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,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
9 changes: 8 additions & 1 deletion doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,14 @@ returned string, each delimited by a space.
util.format('%s:%s', 'foo', 'bar', 'baz'); // 'foo:bar baz'
```

If the first argument is not a format string then `util.format()` returns
Any non-object and non-symbol excessive argument will **not** have
`util.inspect()` called on them.

```js
util.format('%s', 'foo', () => true); // 'foo () => true'
```

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 b687f17

Please sign in to comment.