console.log () utilities

8

I was doing a refactoring in a code made in the MVC format, leaving the code more readable, eliminating duplicate code and deleting variables and API's that were no longer being used.

By deleting some " console.log(algo.aqui) ", I was asked why I deleted them, I promptly replied that it was something that one of the thousands of programmers who had already moved there had forgotten after checking and validating some value in the console.

He informed me that console.log() is not something used only to validate the value of a variable, which also has its applications on both the front end and the back end of the application.

When searching I did not find much.

Then I would like to know:

  • What are the console.log() utilities in the front-end
  • What are the console.log() utilities in the backend?
  • What are the effects that lead to its use? What does it differ from simply passing the variable?
asked by anonymous 07.06.2017 / 19:01

5 answers

9

console.log will call the log method of the console object.

  

Congratulations Captain Obvious, this information has changed my life!

Easy, young man. It turns out that the implementation of the console object is different in every environment.

It is safe to say that, in the most normal case, the console involved is that of the browser. But depending on your environment, this object can write data in different places. Your application can be run in a development or testing environment, rather than the browser. In these cases, the console on which the data will be written will be that of the tool.

Already for the backend: the console can be an external window. While the application is running, the administrator can get an idea of what happens underneath the cloths. This is useful for those who work with Javascript on the server (see node.js).

    
07.06.2017 / 20:04
4

Good afternoon

As the above mentioned people used basically as a debugger of your code, but I will give an example where console.log () helps a lot, I currently work with frameworks like Angular and Vue.js, with these frameworks we create several layers in our frontend (Controller, Service, Factory, etc) with the console.log () we can analyze the state of the data being trafficked between the layers, this is important because we can see where and when the data are being processed and changed.

Note that the console object also has other methods, such as:

  • console.error ()
  • console.info ()
  • console.debug ()
  • console.profile ()

See you later.

    
07.06.2017 / 20:34
3

This is a JavaScript feature used for debugging.

It generates logs that can be queried in the browser console.

In Google Chrome, press CTRL + SHIFT + I, choose "console." This is where the logs will print.

Each browser has a specific console. Note that browsers in older versions do not support this feature.

Utility on the backend? What I know is null as it is a frontend feature between JavaScript and the browser.

  

What are the effects that lead to its use? What it differs from   simply pass the variable?

There is nothing to compare with "variable passing" because they are very different things. It is merely an aid to debugging scripts. Previously we had to use alert() which became a problem in an infinite loop loose by mistake, for example, because the browser kept the alert() infinitely. What's more, it is quiet and can even make you active in the production environment, as long as it does not compromise security.

The utility in leaving active is that it even makes it easier to support a customer. A customer who complains that they can not navigate a page, you can ask the customer to make a printscreen of the console log. This helps a lot especially when the client is a layperson and does not know how to say what is going on.

One thing you should be aware of is that browsers have the capabilities to maintain a log history. If you saved sensitive data logs it is a serious security risk because a malicious person with access to the victim's computer can easily see the console logs.

    
07.06.2017 / 19:36
1

Hello I use Javascript a lot, today the console.log for me has the function of validating if some routines are working as they should. Example I have a multi-calculations application to sell products and whenever a calculation is done it gives a log with console.log an information containing how the calculation was done. And this information is sent to a file for future analysis.

I do not know if it would be a usability of console.log, but stay put.

    
07.06.2017 / 19:35
0

The Console.log is only used to debug information in brownsers (Firefox with Firebug, Chrome, IE8).

    
07.06.2017 / 19:37