JavaScript Output

innerHTML is used to write in an HTML element.
document.write() is used to write for HTML output.
window.alert() is used to write for an alert box.
console.log() is used to write into browser console.

Basic example of innerHTML

To access the HTML element using JavaScritp the innerHTML method is used. While id is used to target the HTML element.

<!DOCTYPE html>
<html>
<body>
<h2>Example of JavaScript</h2>
<p>Paragraph no. 1</p>
<p id="demo">
</p>
<script>
document.getElementById("demo").innerHTML ="Paragraph no. 2"; </script>
</body>
</html>

Output of above code

Example of JavaScript

Paragraph no. 1


Basic example of document.write()

JavaScript method document.write() is mostly used for testing purposes.

<!DOCTYPE html>
<html>
<body>
<h2>Example of JavaScript</h2>
<p>Paragraph no. 1</p>
<script>
document.write("Paragraph no. 2"); </script>
</body>
</html>

Output of above code

Example of JavaScript

Paragraph no. 1


Basic example of window.alert()

JavaScript method window.alert() is used display alert box on the clicking of spefic button or link.

<!DOCTYPE html>
<html>
<body>
<h2>Example of JavaScript</h2>
<p>Paragraph no. 1</p>
<script>
<button type="button" onclick="window.alert('Paragraph no. 2')">click here</button> </script>
</body>
</html>

Output of above code

My First Web Page

My first paragraph.


Basic example of console.log()

JavaScript mehtod console.log() is used to display data in browser.

<!DOCTYPE html>
<html>
<body>
<h2>Example of JavaScript</h2>
<p>Paragraph no. 1</p>
<script>
console.log("paragraph no. 2."); </script>
</body>
</html>








The Best

Comment here

If you have any query, if you want to know something about any of technical course related to computer science field, if you have any suggestion about relevant to uploaded content or if you anything wrong here (any mistake in content) than please contact us. Keep in mind, comment should be according to community guidelines.