File tree 1 file changed +24
-2
lines changed 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -9,8 +9,30 @@ Prints to stdout with newline. This function can take multiple arguments in a
9
9
10
10
console.log('count: %d', count);
11
11
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
+
14
36
15
37
### console.info()
16
38
You can’t perform that action at this time.
0 commit comments