Skip to content

Instantly share code, notes, and snippets.

@nicohsieh
Last active June 6, 2018 17:49
Show Gist options
  • Save nicohsieh/78aa7f182ad20183e60d27abded1335d to your computer and use it in GitHub Desktop.
Save nicohsieh/78aa7f182ad20183e60d27abded1335d to your computer and use it in GitHub Desktop.
console API memo

Formatted log message

Use %c as a specficier to format with CSS style.

console.log(`%c${myText}`, 'color: red; background: black;');

Group log

Console groups can be nested.

console.group();
console.log();
// ...
console.groupEnd();
console.groupCollapsed();
console.log('something');
// ...
console.groupEnd();

Log Arrays

console.log(arr); // yup, we all know this one!
console.dir(arr); // more JSON like output
console.table(arr); // table style output

Different error levels

console.info();
console.warn();
console.error();

Stack trace

Print out the functional call stack.

function funcA() {
  console.trace();
}

Test Time

Similar purpose as performance.now

console.time('funcA');
funcA();
console.timeEnd('funcA');

Test CPU profile

Monitor CPU profile of a certain function. This is super cool!

console.profile('funcA');
funcA();
console.profileEnd('funcA');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment