console.log 和 console.dir的区别

209 阅读1分钟

console.log 可以在控制台打印输出结果。对于html来说打印的是body的内容树。

console.dir可以在控制台显示指定javascipt对象的属性,打印处该对象的所有属性和属性值。对于html来说打印的是body树种的所有属性和方法。

  • console.log prints the element in an HTML-like tree
  • console.dir prints the element in a JSON-like tree

Specifically, console.log gives special treatment to DOM elements, whereas console.dir does not.

This is often useful when trying to see the full representation of the DOM JS object.

SEE ALSO stackoverflow