codescracker


javascript

JavaScript Output



« Previous Tutorial Next Tutorial »


Here are the possible place where you can write your data using the JavaScript functions describes in the table given below:

Name Description
document.write() used to write into an HTML output
window.alert() used to write into an alert box
innerHTML used to write into an HTML element
console.log() used to write into the browser console

JavaScript window.alert() Example

Here is an example of window.alert() in JavaScript:

<!DOCTYPE html>
<html>
<head>
	<title>JavaScript window.alert() Example</title>
	<script>
		function output_fun1()
		{
			window.alert('Hello JavaScript window.aler()');
		}
	</script>
</head>
<body>

<input type="button" onclick="output_fun1()" value="Click Here"/>

</body>
</html>

Here is the live demo output produced by the above JavaScript program:

JavaScript document.write() Example

Here is an example of document.write() in JavaScript:

<!DOCTYPE html>
<html>
<head>
	<title>JavaScript document.write() Example</title>
	<script>
		function output_fun2()
		{
			document.write('Hello JavaScript document.write()');
		}
	</script>
</head>
<body>

<input type="button" onclick="output_fun2()" value="Click Here"/>

</body>
</html>

Below is the live demo output produced by the above JavaScript program:

JavaScript innerHTML Example

You are free to use the method named, document.getElementById(id), to access an HTML element. Here the id attribute is used to define the HTML element of that id. Here is an example of innerHTML:

<!DOCTYPE html>
<html>
<head>
	<title>JavaScript innerHTML Example</title>
	<script>
		function output_fun3()
		{
			document.getElementById("output_para3").innerHTML = 'Hello, this is an innerHTML';
		}
	</script>
</head>
<body>

<p id="output_para3">This is an outer HTML</p>
<input type="button" onclick="output_fun3()" value="Click Here"/>

</body>
</html>

Here is the live demo output of the above example in JavaScript:

This is an outer HTML

JavaScript console.log() Example

You are free to use console.log() method in JavaScript to display the data in your browser. To activate browser console, just press F12 key and select Console in the menu. Here is an example, uses console.log() method in JavaScript:

<!DOCTYPE html>
<html>
<body>

<script>
	console.log('Hello JavaScript');
</script>

</body>
</html> 

Press F12 button, then click to Console, then there you will watch Hello JavaScript as shown in the below box:

Hello JavaScript

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test