编辑模式

打开控制台,输入以下代码,回车.你会发现,此时整个页面都是可编辑状态,想干什么随你!


document.body.contentEditable=true

你可能不知道的devtools调试技巧_devtools页面可编辑示意图

清除控制台

clear()

你可能不知道的devtools调试技巧_devtools_02clear

结构化输出

补充一点,console.table可以传第二个参数,要显示的序列 console.table(users,["name"])

var users=[
    {id:1,name:"react"},
    {id:2,name:"vue"},
    {id:3,name:"angular"}
]

你可能不知道的devtools调试技巧_devtools_03console.log输出效果图
你可能不知道的devtools调试技巧_devtools_04console.table输出效果图
你可能不知道的devtools调试技巧_devtools_05console.table序列过滤

运行时间测试

var i;
console.time("for 循环测试");
for (i = 0; i < 100000; i++) {
  // 代码部分
}
console.timeEnd("for 循环测试");

i = 0;
console.time("while 循环测试");
while (i < 1000000) {
  i++
}
console.timeEnd("while 循环测试");

你可能不知道的devtools调试技巧_devtools_06耗时比对

分组打印

console.group('云梦江氏');
    console.log('魏无羡');
    console.log('江厌离');
    console.log('江澄');
console.groupEnd();

console.group('义城三人组');
    console.log('晓星尘');
    console.log('宋岚');
    console.log('薛洋');
console.groupEnd();

你可能不知道的devtools调试技巧_devtools_07分组打印效果图

美化打印

function beautyLog(info) {
    console.log(`%c${info}`, `color:${_hexColor()}`)
    function _hexColor() {

        let str = '#';
        let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F'];
        for (let i = 0; i < 6; i++) {
            let index = Number.parseInt(Math.random() * 16);
            str += arr[index]
        }
        return str;
    }
}

beautyLog('hello');
beautyLog('hello');
beautyLog('hello');
beautyLog('hello');
beautyLog('hello');
beautyLog('hello');
beautyLog('hello');

你可能不知道的devtools调试技巧_devtools_08美化打印效果图

主题切换

打开控制台,ctrl+shift+p 调出命令面板,输入theme 在暗黑和明亮两个主题之间进行切换

你可能不知道的devtools调试技巧_devtools_09主题切换你可能不知道的devtools调试技巧_devtools_10黑色主题

格式化打印

var name="冷月心";
var age=18;
var like="coding"
console.log(name,age,like) //冷月心 18 coding

// 加一个大括号试试
console.log({name,age,like}) 

你可能不知道的devtools调试技巧_devtools_11格式化打印