Console Logging in JavaScript

Today, I watched the 7 lesson of “Advanced Logging with the JavaScript Console“. My debugging skill with JavaScript console was enhanced a lot.

Log levels

1
2
3
4
5
console.log()
console.warn()
console.error()
console.info()
console.debug()

Log arguments

We can use the similar formatting in printf of C.

1
console.log('Your age is %d', 5)

Grouping and nesting

We group outputs by name.

1
2
console.group("GroupName");
console.groupEnd("GroupName");

Assert

We can make some assertions with function assert. But it does not mean the error is handled.

1
console.assert(info)

Count

We can count outputs with function count.

1
console.count("name")

Timing

1
2
console.time("name");
console.timeEnd("name");

Table

1
console.table(obj)
文章目录
  1. 1. Log levels
  2. 2. Log arguments
  3. 3. Grouping and nesting
  4. 4. Assert
  5. 5. Count
  6. 6. Timing
  7. 7. Table
,