JavaScript Console Log() Method

JavaScript Console Log() Method

In this article, I am going to discuss JavaScript Console Log() Method with Examples. Please read our previous article where we discussed JavaScript Console Info() Method with Examples.

JavaScript console.log() Method

The console.log() method is very important while testing and writing code. Because most of the time we use the console.log() method to understand other developers’ code. The console.log() method is used to write logs / a message to the web console. This method is used for testing purposes. We can use any data type inside the log() method, whether it is a string, array, object, boolean, etc.

Syntax: console.log(message);

Parameters:
  1. message – This parameter contains the message to write to the web console.
Example to Understand JavaScript Console Log() Method
<html>
<head>
    <title>JavaScript console log() method example</title>
</head>
<body>
    <script>
        //sample code1
        var student = {
            course: "JavaScript",
            price: "5000"
        };
        console.log(student, 'console.log- sample code 1');

        //sample code2
        console.log('xyz');
        console.log(10);
        console.log(true);
        console.log(null);
        console.log(undefined);
        console.log([10, 20, 30, 40]); // array inside log
        console.log({ a: 10, b: 20, c: 30 }); // object inside log
    </script>
</body>
</html>

Output: Press F12 and go to the Console section

Example to Understand JavaScript Console Log() Method

In the next article, I am going to discuss JavaScript Console Table() Method with Examples. Here, in this article, I try to explain JavaScript Console Log() Method with Examples. I hope this article will help you with your need. I would like to have your feedback. Please post your feedback, question, or comments about this article.

Leave a Reply

Your email address will not be published. Required fields are marked *