console.log(object [, object, ...])

Displays a message in the console. You pass one or more objects to this method, each of which are evaluated and concatenated into a space-delimited string. The first parameter you pass to log() may contain format specifiers, a string token composed of the percent sign (%) followed by a letter that indicates the formatting to be applied.

Dev Tools supports the following format specifiers:

Format Specifier Description
%s Formats the value as a string.
%d or %i Formats the value as an integer.
%f Formats the value as a floating point value.
%o Formats the value as an expandable DOM element (as in the Elements panel).
%O Formats the value as an expandable JavaScript object.
%c Formats the output string according to CSS styles you provide.

Basic example:

console.log("App started");

An example that uses string (%s) and integer (%d) format specifiers to insert the values contained by the variables userName and userPoints:

console.log("User %s has %d points", userName, userPoints);

An example of using the element formatter (%o) and object formatter (%O) on the same DOM element:

console.log("%o, %O", document.body, document.body);

The following example uses the %c format specifier to colorize the output string:

console.log("%cUser %s has %d points", "color:orange; background:blue; font-size: 16pt", userName, userPoints);

console.profile([label])

When the Chrome DevTools is open, calling this function starts a JavaScript CPU profile with an optional label.To complete the profile, call console.profileEnd(). Each profile is added to the Profiles tab.

In the following example a CPU profile is started at the entry to a function that is suspected to consume excessive CPU resources, and ended when the function exits.

function processPixels() {  console.profile("Processing pixels");  // later, after processing pixels  console.profileEnd();}

console.profileEnd()

Stops the current JavaScript CPU profiling session, if one is in progress, and prints the report to the Profiles panel.

console.profileEnd()

See console.profile() for example use.

console.time(label)

Starts a new timer with an associated label. When console.timeEnd() is called with the same label, the timer is stopped the elapsed time displayed in the Console. Timer values are accurate to the sub-millisecond.

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");

Note: The string you pass to the time() and timeEnd() methods must match for the timer to finish as expected.

console.timeEnd(label)

Stops the timer with the specified label and prints the elapsed time.

For example usage, see console.time().

console.timeStamp([label])

This method adds an event to the Timeline during a recording session. This lets you visually correlate your code generated time stamp to other events, such as screen layout and paints, that are automatically added to the Timeline.

See Marking the Timeline for an example of using console.timeStamp().

console.trace(object)

Prints a stack trace from the point where the method was called, including links to the specific lines in the JavaScript source. A counter indicates the number of times that trace() method was invoked at that point, as shown in the screen shot below.

It is also possible to pass in arguments to trace(). For example:

console.warn(object [, object, ...])

This method is like console.log() but also displays a yellow warning icon along with the logged message.

console.warn("User limit reached! (%d)", userPoints);

debugger

The global debugger function causes Chrome to stop program execution and start a debugging session at the line where it was called. It is equivalent to setting a "manual" breakpoint in the Sources tab of Chrome DevTools.

Note: The debugger command is not a method of the console object.

In the following example the JavaScript debugger is opened when an object's brightness() function is invoked:

brightness : function() {    debugger;    var r = Math.floor(this.red*255);    var g = Math.floor(this.green*255);    var b = Math.floor(this.blue*255);    return (r * 77 + g * 150 + b * 29) >> 8;}

最新文章

  1. 【Java并发系列02】Object的wait()、notify()、notifyAll()方法使用
  2. 【python】Redis介绍及简单使用
  3. 今天发现之前瑞乐做的登录和注册居然都是用的get请求,瞬间出了一身冷汗.
  4. Debugging WebLogic Server Applications Using Eclipse and the WebLogic-Plugin
  5. 架构系列:ASP.NET 项目结构搭建
  6. 深入学习 memset 函数
  7. WPF 之 鼠标双击事件
  8. Java学习第七篇:与运行环境交互
  9. Exception与相关
  10. 洛谷P1407 工资
  11. Setup Tensorflow with GPU on Mac OSX 10.11
  12. EtherChannel Cisco 端口聚合详解
  13. Linux下Apache https认证
  14. Python os.chdir() 方法
  15. 使用Canvas制作画图工具
  16. myEclipse全局搜索时报错
  17. 从新安装SQLserver 过程中报错问题合集
  18. [CodeForces - 447E] E - DZY Loves Fibonacci Numbers
  19. Flash:彻底理解crossdomain.xml、跨swf调用。
  20. Android 底部按钮BottomNavigationView + Fragment + viewPager 的使用(一)

热门文章

  1. GoAccess安装和使用介绍
  2. android 内存泄露测试
  3. svn与git区别简介,git分支操作在mac客户端soureTree和使用命令行如何实现
  4. xwork-conversion.properties 目前没有解决方案
  5. Zero to One书摘
  6. 爬虫3_python2
  7. python_101_类方法
  8. s///|s()()i|/i|/g|\U|\u|\L|\l|\U\l|split|join|匹配到hash|匹配到变量|`date`|$^I
  9. JQuery EasyUI学习记录(二)
  10. LINQ与反射