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!");


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!");


Recently Added