JavaScript #3 – Console

In this article, we learn how to use the most powerful tool, what each JavaScript developer needs to understand. I am writing about the console. Both, in-browser and Node (we learn this technology in future), consoles are a very useful tool. They inform us about issues with our code, show information, warnings and critical errors.

How to use the console? It’s very simple. If you have already installed one of popular web browsers like Chrome, Firefox, Opera or Edge just open it by pressing an F12 key on your keyboard (default in Chrome, Firefox and Opera Neon). In variety browsers, a shortcut may be different. So, just search in documentation.

So, when you open the console, you should see something like this:

So, what we can learn from this part of the browser?
1 – clear console
2 – filter – this is option, that help us to find specific logs
3 – context of logs
4 – don’t clear logs on page refresh

From the top, you see several types of console logs. The first (red) log is an error. This log contains information about the error which occurred – with a path to file and line.

Second (with the (i) symbol is information. Third log (yellow) is warning information. It’s not critical so, your code may work without fixes. However, you consider fix it.

Fourth – without any icons on penultimate line is default log. This type of logs is usually used by developers to debug (fixing and removing bugs and errors from code). In this case, I debug result of math operation 1+1.

Furthermore, console object provides one more log method, it is debugging log.

To conclude, in this article we learn what is the console, and what types of logs you should expect. So, learning in theory is one, a different kettle of fish is practice. In next article, we are going to start practise and learn how to write “Hello World” script.

 

Herbaciarz

 

Leave a Reply

Your email address will not be published. Required fields are marked *