log

여러 level의 로그가 존재하는 이유는 브라우저에서 개발자가 level에 따라 로그를 구별해서 보기 위함과 더불어 서버를 배포할 때 wran, error 와 같은 경우에 로그를 구분 지어 기록을 남기기 위해 존재한다. 그래서 level 별로 로그의 출력을 막을 수도 열어 둘 수도 있다.

console.log('log');   // 개발
console.info('info'); // 정보
console.warn('warn'); // 경보
console.error('error'); // 에러, 사용자 에러, 시스템 에러

assert

조건이 거짓이면 출력

console.assert(2 === 3, 'not same!'); // Assertion failed: not same!
console.assert(2 === 2, 'same!');

print object

table : table 형태로 출력

dir : 옵션에 따른 객체 출력

const student = { name: 'ellie', age: 20, company: { names: 'AC' } };

console.table(student);
// ┌─────────┬───────┬─────────┐
// │ (index) │ names │ Values  │
// ├─────────┼───────┼─────────┤
// │  name   │       │ 'ellie' │
// │   age   │       │   20    │
// │ company │ 'AC'  │         │
// └─────────┴───────┴─────────┘
console.dir(student, { showHidden: true, color: false, depth: 0 });
// { name: 'ellie', age: 20, company: [Object] }

measuring time

time & timeEnd : 같은 레이블이 시작되어 끝날 때 까지 얼마나 걸렸는지 시간을 확인할 수 있다.

성능을 확일할 때 유용하다.

레이블명을 동일하게 작성해야 한다.

console.time('for loop');
for (let i = 0; i < 10; i++) {
  i++;
}
console.timeEnd('for loop');