Day 9— Console

What I learned from JavaScript 30(Course Web — https://javascript30.com/)

Besides console.log(), there are many other console things could be used to debug.

Here’s a list on MDN:

En-MDN: Console

As well as some examples from this course, Coding on Github .

I list here what I feel the most useful:

console.log()

The most useful one. It’s good to know that there are three different console.log().

Regular one

console.log(‘HELLO’)

String parameter one

console.log(‘Hello %s’,’world’)

%s will be replace by second parameter.

Styled one

console.log(‘%c Watch out!’, ‘font-size:40px; color:red’)

%c must be at the beginning of first parameter. You will get a big red ‘Watch out’ text in consoler.

console.table()

This will return the data in a form of table. It’s the most efficient way to check the array that including objects.

console.time()

console.time(‘fetching data’);
 fetch(‘https://api.github.com/users/wesbos')
 .then(data => data.json())
 .then(data => {
 console.timeEnd(‘fetching data’);
 console.log(data);
 });

Sometimes we need to consider timing efficiency of our codes, console.time() will help.

console.assert()

It’s useful to test something without checking the ‘Elements’, though the latter way is easier and faster.