前端开发之:debug技巧-console

Console Object Methods

Method Description Chinese Translation
assert() Writes an error message to the console if the assertion is false 如果断言为false,则向控制台写入错误消息
clear() Clears the console 清除控制台
count() Logs the number of times that this particular call to count() has been called 记录调用count()的次数
error() Writes an error message to the console 向控制台写入错误消息
group() Creates a new inline group in the console. This indents following console messages by an additional level, until console.groupEnd() is called 在控制台中创建一个新的内联组。这将使后续的控制台消息缩进一个级别,直到调用console.groupEnd()
groupEnd() Exits the current inline group in the console 退出控制台中的当前内联组
info() Informative logging of information 信息日志
log() For general output of logging information 一般输出日志信息
table() Displays tabular data as a table 将表格数据显示为表格
time() Starts a timer (can track how long an operation takes) 启动计时器(可以跟踪操作所需的时间)
timeEnd() Stops a timer that was previously started by console.time() 停止之前由console.time()启动的计时器
trace() Outputs a stack trace 输出堆栈跟踪
warn() Outputs a warning message 输出警告消息

examples of console object methods:

// log() method
console.log("This is a log message");

// error() method
console.error("This is an error message");

// warn() method
console.warn("This is a warning message");

// info() method
console.info("This is an info message");

// assert() method
console.assert(2 + 2 = 5, "2 + 2 does not equal 5");

// clear() method
console.clear();

// count() method
console.count("Count");
console.count("Count");
console.count("Count");

// group() and groupEnd() methods
console.group("Group");
console.log("Group message 1");
console.log("Group message 2");
console.groupEnd();

// table() method
console.table(["Apple", "Orange", "Banana"]);

// time() and timeEnd() methods
console.time("Timer");
for (let i = 0; i < 1000000; i++) {
// some code
}
console.timeEnd("Timer");

// trace() method
function foo() {
function bar() {
console.trace();
}
bar();
}
foo();

上一篇
下一篇