Open In App

How to print debug messages in the Google Chrome JavaScript Console?

Printing in the console is pretty easy all we have to know is how to activate the console on the chrome for viewing. The Console is always active all we are doing is making it visible to the front-end. A console is an object which provides access to the browser’s debugging console. Console object has many methods which help us to print customized debugging. Here, are the following methods:

Click on F12 after running the script and it opens the Developer Tools, navigate to the Console tab, which will be on the top menu.



Example 1: 




<!DOCTYPE html>
<html>
 
<body>
 
    <h2>Debugging in Console</h2>
 
    <p>On Clicking the below button,
      myFunction() invokes and prints in the console.</p>
    <input type="button"
           onclick="myFunction()"
           value="Tony send signal to Quill(console)">
    <!--button-->
    <script>
        function myFunction() {
            //prints in console
            console.log("log:Tony sent a message");
           
            //prints in console
            console.info("info:Quill received.");
        }
    </script>
 
</body>
 
</html>

Output: Before:



Output1

After clicking the button:

output2

Example 2: Check out the console.table() for better understanding of methods. 




<!DOCTYPE html>
<html>
 
<body>
 
    <h2>Debugging in Console</h2>
 
    <p>On Clicking the below button,
      myFunction() invokes and prints in the console.</p>
    <input type="button"
           onclick="myFunction()"
           value="who are the guardians?">
    <script>
        function myFunction() {
            console.table(["Quill", "Gamora", "Drax",
                           "Groot", "Rocket", "mantis"]);
        }
    </script>
 
</body>
 
</html>

Output Before:

output1

After Clicking the button:

output2


Article Tags :