JS Output

JavaScript

Share

In this tutorial we will learn about JavaScript output.

Some of the possible ways we can display output in JavaScript is covered in this tutorial.

console.log()

We use the console.log() method to display the output in the browser console.

How to open browser console?

Chrome: View -> Developer -> Developer Tools

Firefox: Tools -> Web Developers -> Web Console

Safari: Developer -> Show Error Console

Or, simply right click on the page and select Inspect / Inspect Element and then click on the Console tab.

In the following example "Hello World!" will be printed as output in the browser console.

console.log("Hello World!");


console.info()

We use the console.info() method to display some informative info in the browser console.

console.info("This is an info message.");

console.error()

We use the console.error() method to display error message in the browser console.

console.error("This is an error message.");

console.warn()

We use the console.warn() method to display warning message in the browser console.

console.warn("This is a warning message.");

document.write()

We use the document.write() method to output in the HTML document.

In the following example "Hello World!" will be displayed in the HTML document page.

document.write("Hello World!");


window.alert()

We use the window.alert() method to display the output in an alert box.

In the following example we will get an alert box with output "Hello World!".

window.alert("Hello World!");