console.log有什么用?
请用一个代码示例解释如何在JavaScript中使用它。
console.log有什么用?
请用一个代码示例解释如何在JavaScript中使用它。
当前回答
举个例子——假设你想知道哪行代码可以运行你的程序(在它崩溃之前!),只需输入
console.log("You made it to line 26. But then something went very, very wrong.")
其他回答
注意:在您的产品代码中保留对控制台的调用将导致您的站点在Internet Explorer中崩溃。永远不要打开包装。参见:https://web.archive.org/web/20150908041020/blog.patspam.com/2009/the-curse-of-consolelog
A point of confusion sometimes is that to log a text message along with the contents of one of your objects using console.log, you have to pass each one of the two as a different argument. This means that you have to separate them by commas because if you were to use the + operator to concatenate the outputs, this would implicitly call the .toString() method of your object. This in most cases is not explicitly overriden and the default implementation inherited by Object doesn't provide any useful information.
在控制台尝试的例子:
>>> var myObj = {foo: 'bar'}
undefined
>>> console.log('myObj is: ', myObj);
myObj is: Object { foo= "bar"}
然而,如果你试图连接信息文本消息与对象的内容,你会得到:
>>> console.log('myObj is: ' + myObj);
myObj is: [object Object]
请记住,console。log实际上可以接受任意多的参数。
这与jQuery无关。console.log()引用控制台对象的日志函数,该函数提供了将信息记录到浏览器控制台的方法。这些方法仅用于调试目的,不应依赖于将信息呈现给最终用户。
console.log与jQuery无关。
它将消息记录到调试控制台,例如Firebug。
它用于将(传递给它的任何内容)记录到Firebug控制台。主要用途是调试JavaScript代码。