// Basic Usage
console.log ( 'The most common use of \ n newline');
. Console error ( 'output an error message will be displayed in red');
. Console The warn ( 'print a warning message will be displayed in yellow');
. Console info ( 'Print general information ');
. console Clear (); // Clear display console above
// Advanced Usage
console.assert (false, 'determines false information was displayed'); // console.assert (bool, "info") If bool is false to print or not to print out the info
console.table ([[ 'China', ' U.S. '], [' good ']]); // array or passed objects displayed in tabular form
function fn () {console.trace () ;} // call chain Fn2 print () call fn1 (), fn1 () call Fn ()
function Fn1 () {Fn ();}
function Fn2 ( ) {Fn1 ();}
Fn2 ();
// formatted output
-
Format flag console.log supported are:
-
% S placeholder
-
Or an integer of% d% i
-
% F float
-
% O% O object Object
-
% C css styles
the console.log ( 'D%% +% D = D', l, 2,3);
// O% O% when the node is not the same print dom the console.log ( '% O', the document.body); Console .log ( '% O', the document.body);
// behind% C content, increases css style
@ attachment: console.log output hyperlink is automatically recognized and adding gray font color and underline style, and this can not be covered with C%
the console.log ( 'C 456 123%', 'font-size: 36px; Color: Red;');
the console.log ( '123. 4% C http://www.google.com C 789% 56 is', 'font-size: 20px; Color: # ff8400;', 'font-size: 12px; Color: # 000');
// // load picture using css style not directly setting the width and height style, line-height image height, and then transferred padding
the console.log ( '% C', 'background-image: URL ( "http://iyeslogo.orbrand.com/150902Google/005.gif"); background-size: 120% 120%; background-repeat : no-repeat; background-position: center center; line-height: 60px; padding: 30px 120px; ');
// Advanced Usage
//计时,单位毫秒 console.time(); for(var i=0;i<100000;i++){ var j=i*i; } console.timeEnd(); //统计代码或函数被调用了多少次 var fn_ = function(){ console.count('hello world'); } for(var i=0;i<5;i++){ fn_(); } //查看内存使用情况,是属性,不带括号 //console.memory; //在浏览器开发者工具中使用 //分组输出,可嵌套 console.group('分组1'); console.log('语文'); console.log('数学'); console.group('其他科目'); console.log('化学'); console.log('地理'); console.log('历史'); console.groupEnd('其他科目'); console.groupEnd('分组1');