HTML | DOM console.log() Method

The console.log() method in HTML is used for writing a message in the console. It indicates an important message during testing of any program. The message is sent as a parameter to the console.log() method.

Syntax:

console.log( message )

Parameters: This method accepts single parameter message which is mandatory and used to specify the information to be written on the console.



Below programs illustrate the console.log() method in HTML:
Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM console.log() Method</title>
    <style>
        h1 {
            color: green;
        }
          
        h2 {
            font-family: Impact;
        }
          
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>DOM console.log() Method</h2>
    <p>
        To view the message in the console 
        press the F12 key on your keyboard.
    </p>
    <p>
        To view the message, double click
        the button below:
    </p>
    <br>
    <button ondblclick="log_console()">
        View Message
    </button>
    <script>
        function log_console() {
            console.log
                ("GeeksforGeeks is a portal for geeks.");
        }
    </script>
</body>
  
</html>

chevron_right


Output:

Console View:

Example 2: Displaying an object while using console.log() method

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <title>DOM console.log() Method</title>
    <style>
        h1 {
            color: green;
        }
          
        h2 {
            font-family: Impact;
        }
          
        body {
            text-align: center;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>DOM console.log( ) Method</h2>
    <p>
        To view the message in the console
        press the F12 key on your keyboard.
    </p>
    <p>
        To view the message, double click
        the button below:
    </p>
    <br>
    <button ondblclick="log_console()">
        View Message
    </button>
    <script>
        function log_console() {
            var MyElement = {
                Product: "Coca Cola",
                Type: "Beverage"
            };
            console.log(MyElement);
        }
    </script>
</body>
  
</html>

chevron_right


Output:

Console View:

Supported Browsers: The browser supported by console.log() method are listed below:

  • Google Chrome
  • Internet Explorer 8.0
  • Firefox 4.0
  • Opera
  • Safari


My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.