JavaScript console.log() Method

The console.log() method is used for logging messages to the console. It is a debugging tool available in most web browsers. It is used during development to output information about the state of the program.

Syntax:

console.log();

Example: This example uses the console.log() property to display data. 

HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <title>JavaScript Output</title>
</head>

<body>
    <h2>
        Display Output using console.log() Method
    </h2>
    
    <!-- Script to use console.log() -->
    <script>
        console.log("Hello Geeks!");
    </script>
</body>

</html>

Output:

JavaScript Output

Understanding how to handle JavaScript output is essential for effective web development. JavaScript provides several methods to display output, such as console.log(), alert(), document.write(), and manipulating HTML elements directly. Each method has its specific use cases, whether for debugging, user notifications, or dynamically updating web content. This guide will explore various JavaScript output methods, demonstrating how and when to use them effectively.

Similar Reads

JavaScript Output Display Properties

There are primarily multiple distinct methods for displaying output in JavaScript. Although there are other methods for output display, they are not advisable, so it is recommended to refrain from using alternative output approaches....

1. JavaScript innerHTML Property

The innerHTML property is used with HTML element. JavaScript can be used to select an element using the document.getElementById(id) method, and then use the innerHTML property to display the output on the specified element (selected element)....

2. JavaScript console.log() Method

The console.log() method is used for logging messages to the console. It is a debugging tool available in most web browsers. It is used during development to output information about the state of the program....

3. JavaScript document.write() Method

To use the document.write(), simply call this method and provide the content you want to be written to the document. This method is often used for directly adding content to the HTML document while it is being parsed....

4. JavaScript window.alert() Method

The window.alert() method is used to display an alert box with a specified output (or message) and an OK button....

5. JavaScript window.print() Method

The window.print() method is used to open the browser’s print dialog, allowing the user to print the current page. JavaScript does not contain any default print object or methods....

6. JavaScript window.prompt() Method

The window.prompt() method is used to display a dialog box that prompts the user input. It returns the text entered by the user as a string. It doesn’t display output directly but captures user input....