The Console API
The Console API Is typically baked into web browsers and even in VSCode and other coding development environments. The console is itself a Read-Evaluate-Print Loop environment or REPL for short (Horcasitas, 2021). It can also be used for running code right within it. It also allows the user to see errors in the code as it is run as well as anything the programmer has requested to output to the console using an array of different commands. Nothing that is sent to the console will show up on the webpage or program, so it’s great for debugging (Flanagan, 2020).
As a REPL, the user can type in simple calculations as well as JavaScript code and run it before adding it to their code. This can be very useful in testing just a snippet of code to see if it works before plugging it into the rest of the program.
Within the code, the programmer can add commands to output information to the console in strategic areas in order to make sure the code is running as intended. For example, in a for loop, the simple variable “i” is increased every iteration of the loop. The programmer can send that value of “i” to the console by using console.log(i) to see if the loop is progressing as hoped for. It is also common to use the console to see when a certain portion of the code has been reached.
Get Ace D Baugh’s stories in your inbox
Join Medium for free to get updates from this writer.
Every other line of code does not need to have a console.log to reassure the programmer every line is being run. It should be used sparingly when debugging and when hitting coding milestones. It is also a good practice to see how many times a portion of code is being run. A good way to do this is with console.count.
That being said, console.log and the other commands that can be used are no match for the other tools available in Chrome DevTools or JavaScript debugger in Firefox (Lmsc, 2021). They have great ways to pause at certain points in the code and see all variable values as they run into them.
References
Flanagan, D. (2020). JavaScript: The definitive guide: Master the world’s most-used programming language. O’Reilly Media.
Horcasitas, J. (2021, July 30). What is repl? DigitalOcean. Retrieved June 21, 2022, from https://www.digitalocean.com/community/tutorials/what-is-repl
Lmsc, B. (2021, September 3). Stop using console.log. Medium. Retrieved June 21, 2022, from https://medium.com/@benlmsc/stop-using-console-log-d281a900dedb




