原网页:https://developers.google.com/chrome-developer-tools/docs/console
- console.assert(expression, object) 根据条件判断,决定是否输出错误消息
- console.clear() 清理窗口
- console.count(label) 计数器
- console.debug(object [, object, ...]) 等同于debug.log
- console.dir(object) 使用JavaScript对象格式输出object,等同%O
- console.dirxml(object) 使用XML模式输出object,等同%o
- console.error(object [, object, ...]) 输出错误消息
- console.group(object[, object, ...]) 群组输出(初始展开)
- console.groupCollapsed(object[, object, ...])群组输出(初始展开)
- console.groupEnd() 结束群组输出
- console.info(object [, object, ...])等同于debug.log
- console.log(object [, object, ...])
- console.profile([label]) JavaScript CPU模拟
- console.profileEnd()
- console.time(label) 时间测量
- console.timeEnd(label) 结束时间测量
- console.timeStamp([label])
- console.trace() 跟踪函数
- console.warn(object [, object, ...]) 输出警告消息
- debugger 停止执行,等同设置断点
log正常输出
error输出错误消息
wran输出警告消息
assert当函数第一个参数为假时,输出错误消息(第二个参数)
console.error("Error: %s (%i)", "Server is not responding",500);
console.warn('Warning! Too few nodes (%d)', a.childNodes.length);
console.assert(list.childNodes.length < 500, "Node count is > 500");
group/groupEnd群组输出:把两个函数之间的输出组合为一条消息输出出去(最初展开模式)
使用groupCollapsed替换group,则最初输出时不展开
var user = "jsmith", authenticated = false;
console.group("Authentication phase");
console.log("Authenticating user '%s'", user);
// authentication code here...
if (!authenticated) {
console.log("User '%s' not authenticated.", user)
}
console.groupEnd();
群组输出中可以嵌套
var user = "jsmith", authenticated = true, authorized = true;
// Top-level group
console.group("Authenticating user '%s'", user);
if (authenticated) {
console.log("User '%s' was authenticated", user);
// Start nested group
console.group("Authorizing user '%s'", user);
if (authorized) {
console.log("User '%s' was authorized.", user);
}
// End nested group
console.groupEnd();
}
// End top-level group
console.groupEnd();
console.log("A group-less log trace.");
字符串替换符
Format specifier | Description |
---|---|
%s | 字符串 |
%d or %i | 整数 |
%f | 浮点数 |
%o | 可展开的DOM节点Formats the value as an expandable DOM element (as in the Elements panel). |
%O | 可展开的JavaScript对象Formats the value as an expandable JavaScript object. |
%c | 输出时使用CSS样式Applies CSS style rules to output string specified by the second parameter. |
console.log("%cUser %s has %d points", "color:orange; background:blue; font-size: 16pt", userName, userPoints);
time,timeEnd时间测量
console.time("Array initialize");
var array= new Array(1000000);
for (var i = array.length - 1; i >= 0; i--) {
array[i] = new Object();
};
console.timeEnd("Array initialize");