Difference console.dir () and console.log () in

console.log () can replace the alert () or document.write (), when using console.log () script on the page, print out the information in the browser console.

console.dir () to display an object for all properties and methods.

 

I wrote a simple example:

HTML:

< The Button > console.log print trigger objects </ the Button > 
< the Button > console.dir print trigger objects </ the Button >

JS: // difference of console.log and console.dir 

// syntax console.dir (object); // only one parameter 
// In order to facilitate the observation can open the browser that comes with the console to see // The following examples // print out of the body tag of html element console.log (document .body, 'BodyHTML' ); // print out the target body DOM
// console.dir (document.body, 'get out');
console.dir (the document.body ); // examples of dicarboxylic var oButton = document.getElementsByTagName ( 'Button' ); oButton [ 0] = .onclick function (Event) { the console.log (event.target, 'Button1' ); } oButton [ . 1] .onclick = function (Event) { console.dir (event.target, 'Button2'); }

 

effect:

After the program is loaded, it will immediately print out the body of the HTML and Object

 

 

Also click the first button and the second button are printing:

Now the difference is very obvious, right! So sometimes we need to be used when the object is to find ways console.dir of () to print.

 

Detailed methods console can take a look at this text:  https://segmentfault.com/a/1190000004528137

 

Guess you like

Origin www.cnblogs.com/taohuaya/p/10960418.html