JavaScript: output to the console

The tutor tests JavaScript code using the console.

I’ve long known about the JavaScript console, and use it sometimes for debugging. However, I didn’t know to use if for testing – until now.

In the past, I’d build a rudimentary web page around a JavaScript function, sending the output to a div using innerHTML. However, for checking continuity and logic, sending output to the console might be simpler. Testing it today, I’d just open Notepad, type


to be

console.log(Output you want to see);


then save the file as html and point the browser to it. Of course, at first, I’d just get a blank screen. F12 opens the developer tools, then clicking Console shows the output.

In the JavaScript code, the command

console.log(Output you want to see);

sends the output to the console. If for some reason there’s a problem, you know right away: that’s what the console is there to tell you. Therefore, it’s a great testing utility.




Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Tagged with: , , ,

Leave a Reply