概述
向 Web 控制台输出一条消息。
语法
console.log(obj1 [, obj2, ..., objN]); console.log(msg [, subst1, ..., substN]); console.log('String: %s, Int: %d,Float: %f, Object: %o', str, ints, floats, obj) console.log(`temp的值为: ${temp}`)
参数
obj1
...objN
- 一个用于输出的 JavaScript 对象列表。其中每个对象会以字符串的形式按照顺序依次输出到控制台。
msg
- 一个JavaScript字符串,其中包含零个或多个替代字符串。
subst1
...substN
- JavaScript 对象,用来依次替换
msg
中的替代字符串。你可以在替代字符串中指定对象的输出格式。
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
基本功能 | (Yes) | (Yes) | 4.0 (2.0) | 8 | (Yes) | (Yes) |
替代字符串 | (Yes) 28[1] |
(Yes) | 9.0 (9.0) | 10[2] | (Yes) | (Yes) |
Available in workers | ? | (Yes) | 38.0 (38.0) | ? | ? | ? |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
基本功能 | ? | 4.0 (2.0) | ? | ? | ? |
替代字符串 | ? | 9.0 (9.0) | ? | ? | ? |
规范
不属于任何公开的规范