If you are new to the Javascript language and you are wondering how can I display a value on to a web page or show it to the user, you've come to the correct post.

In this blog post, we will see 3 different ways in which you can output from javascript and print the values to show it to the user.

 

 

1. Output Values Using Javascript Console.log()

In the javascript language, we get the log function on the Console.

This log function takes in string parameters which we can use to output values onto the console of the web browser.

Let's see in an example.

 

Example:

 

Result:

output values to console using javascript

 

In the above example, we can see that when we use the console.log() method in javascript, it prints out the output in the console window of the browser.

To open the console window, right click on the web page and click on "Inspect". Then click on the "Console" tab to open the console window.

 

 

2. Output/Print Values Using Javascript Window.alert()

In this method, we use the Window object to notify and display values to the user.

The Window.alert() method also takes a string as a parameter to the method and you can pass in any value as a string to display to the user web page.

When we use Window.alert() method to print in javascript, it opens an alert box on the top of the web browser.

Different browsers have different ways to display the alert box too.

Let's see this in an example.

 

Example:

 

Result:

Print Javascript Using Alert Method

 

 

3. Display Output In Javascript Using .innetHTML

There is another way to display values like strings and numbers on the web page using javascript and that is by using the .innerHTML property.

Elements like paragraphs have .innerHTML properties which you can set via javascript to display your output or print your output to the user.

Let's see this in a example.

 

Example:

 

Result:

Javascript output print using innerHTML