Console 对象
这个对象就是用来在控制台下面打印一些信息而已,挑几个有用但没记牢的方法来玩玩。
console.dir(value): 打印一个对象的详细信息
const buf = Buffer.from('abcdefg');
console.log(buf); // <Buffer 61 62 63 64 65 66 67>
console.dir(buf); // Buffer [ 97, 98, 99, 100, 101, 102, 103 ]
console.time(label) & console.timeEnd(label): 用来统计代码执行时间
let label = 'time';
let str = 'hello';
console.time(label);
while (str.length < 999999) {
str += 'a';
}
console.timeEnd(label); // time: 133.724ms6 个计时器函数
在浏览器上,就有相应的 4 个计时器函数(setInterval、clearInterval、setTimeout、clearTimeout),只不过它们是 window 全局对象的属性。
在 nodejs 中,除过上面的 4 个计时器,还增加了两个(setImmediate,clearImmediate)。
这六个计时器函数被定义在了全局对象 global 下,即可以直接在代码中进行使用。









