JavaScript Tips on using chrome console

Log the variable with variable names

var foo = "a", bar = "b", baz = "c";
console.log({foo, bar, baz});
1
2

Custom CSS in console log

use %c to add css style

console.log('%c My Friends', 'color : orange; font-weight: bold')
1

Create a table for display arrays

console.table([foo, bar, baz]);
1

Check the time for loading

console.time("loop");
let i = 0;
while(i < 1000000) { i++ }
console.timeEnd("loop");
1
2
3
4

Stack trace

Add console.trace() to the function so can trace where the function is executed.

const deleteMe = () => console.trace('bye bye database');
deleteMe();
deleteMe();
1
2
3
Last Updated: 3/4/2019, 12:45:28 AM