Console log statements and alerts in JavaScript

avatar

Troubleshooting is one of the most important skills for any developer. For any programming language, troubleshooting is important. While troubleshooting we go through each and every line of code to make sure the arguments and values are passed correctly or not. There are different machines available to check for a value based on the programming language. Exception handling also plays a vital role in troubleshooting.

I wanted to share something interesting about console log statements and alerts. In one of the recent projects where we had an issue in a production environment that was very unique to the environment, we had to carry out testing directly in the production environment. I was sharing some information about console log statements and alerts with the team members. Their suggestion was to use alerts to track the value that is being passed and that is when I started elaborating about the console log and its advantages.

image.png

Source

Alerts are something that we usually use in the front end JavaScript to check for a value. The alert box will appear like a pop-up and it will not let us proceed with the other activities. It becomes like a blocker to the users. They have to clear the alerts in order to proceed with the other activities in the application. For people who are used to javascript coding in the old days, alert statements are quite common. I remember that during my college days they thought me alert statements to check for a value on the web. I guess that is the same for many people.

Console log statements are more like something that is used in the backend programming where if we have to print value and check, we can do it using console log statements. This is the way in which we can check for values in Node js. Most of the web developers are not used to console log statements and way back alerts were the only significant way to check for a value. Now that browser also has a console, console log statements also make a great significance in front end programming. Especially when browsers were more modernized I guess this can be the ideal way for troubleshooting. We can also use the browser console to write code directly there and get output.

While working on the production issue, we had to do some real-time testing. We had a few test databases in the production environment but if we had to make some changes to the code/JavaScript files, we have to make sure the usability of the clients is not affected. If it was a few years before, I would have also come up with a solution to have an alert but today we have easier ways to troubleshoot. Alert boxes used to be the traditional way of debugging or troubleshooting. But if we use alerts, the client can find it difficult to work and it will be a big impact for them as the code files are common for all the databases.

image.png

Source

It is always better to use console log statements because it will not impact any client experience as there will not be any pop-up or something that stops them from doing any action. This article can be a silly concept for some experienced developers. But, I still remember when I explored this by myself and started using this trick quite frequently. Especially when we are doing sneaky troubleshooting or testing directly on the production environment alongside the client, this could be an ideal way to do it. The client usability and user experience will not be affected and at the same time, we can also troubleshoot our issue easily.



0
0
0.000
0 comments