Most web browsers support writing message to console using console.log() method.
You can also invoke it using following shortcuts :
Windows(IE, Chrome, Firefox)
F12, then click Console tab
Safari : Cmd + Opt + C
Chrome : Cmd + Opt + J
Firefox : Cmd + Opt + K
You can directly type commands in the console after opening it and hit enter.
For example, here we declare and initialize a variable name and print it to the console.
We can log messages in console and check if the program is working as expected.
var newString = "";
var originalString = 'helloworld';
var counter = originalString.length;
newString += originalString.substring(counter - 1, counter);
console.log("Inside loop, iter" + counter + ", string is" + newString);
while (counter > 0);
document.write(originalString + " reversed is " + newString + "!");
helloworld reversed is dlrowolleh!
This is a simple script. But may need to log outputs for complex programs to help with debugging in case of any issues.
Since we have added console.log() in the iteration, it will log the output of each step to console.
© 2016, www.topjavatutorial.com. All rights reserved. On republishing this post, you must provide link to original post