console.log()
方法将打印其括号内的输出“打印”到控制台,这可能是最有用的调试工具。将它放在代码中的关键点可以显示变量的中间值。在查看输出之前,最好先了解输出应该是什么。在整个代码中使用检查点来查看计算状态将有助于缩小问题所在。这是打印'Hello world!'的示例到控制台: console.log('Hello world!');
console.log()
方法打印代码中记录的变量a
的值。 console.log()
来检查变量a
的值。
testString: 'assert(code.match(/console\.log\(a\)/g), "Your code should use console.log()
to check the value of the variable a
.");'
```