Console.dir () can display all properties and methods of an object.
Console.dirxml () is used to display the Html/xml code contained in a node of a Web page.
Vi. Judging if the variable is trueConsole.assert () is used to determine whether an expression or variable is true. If the result is no, a corresponding message is output in the console and an exception is thrown.
1: <script type="text/javascript"> 2: var result = 1; 3: console.assert( result ); 4: var year = 2014; 5: console.assert(year == 2018 ); 6: </script>
1 is a value of 0, is true, and the second is false, displaying an error message on the console
Tracing the call trajectory of the function.Console.trace () is used to track the call path of a function.
1: <script type="text/javascript"> 2: /*函数是如何被调用的,在其中加入console.trace()方法就可以了*/ 3: function add(a,b){ 4: console.trace(); 5: return a+b; 6: } 7: var x = add3(1,1); 8: function add3(a,b){return add2(a,b);} 9: function add2(a,b){return add1(a,b);} 10: function add1(a,b){return add(a,b);} 11: </script>
Console output Information:
Eight, chronograph functionConsole.time () and Console.timeend () are used to display the elapsed time of the code.
1: <script type="text/javascript"> 2: console.time("控制台计时器一"); 3: for(var i=0;i<1000;i++){ 4: for(var j=0;j<1000;j++){} 5: } 6: console.timeEnd("控制台计时器一"); 7: </script>
Run Time is 38.84ms
Performance analysis of Console.profile ()Performance analysis (Profiler) is the analysis of the various parts of the running time, to find out the bottleneck, the method used is Console.profile ().
1: <script type="text/javascript"> 2: function All(){ 3: alert(11); 4: for(var i=0;i<10;i++){ 5: funcA(1000); 6: } 7: funcB(10000); 8: } 9: 10: function funcA(count){ 11: for(var i=0;i<count;i++){} 12: } 13: 14: function funcB(count){ 15: for(var i=0;i<count;i++){} 16: } 17: 18: console.profile(‘性能分析器‘); 19: All(); 20: console.profileEnd(); 21: </script>
Output
Nine console commands to make JS debugging easier