JavaScript Output specifies the ways to display the output of a given JS code. The output can be specified by using four different ways. These are:
1. InnerHTML:- This method is used to access an element. It specifies the HTML content.
Example
<html> <body> <h1>crus4</h1> <p id="Hello"></p> <script> document.getElementById("Hello").innerHTML = 7*5; </script> </body> </html>
Here the id
attribute specifies the HTML element. The property innerHTML
specifies the HTML content.
2. document.write():- This method is used for testing purpose.
Example
<html> <body> <h1>crus4</h1> <script> document.write(7*5); </script> </body> </html>
3. window.alert():- You can also use an alert box to display the content.
Example
<html> <body> <h1>crus4</h1> <script> window.alert("Hello Developers!"); </script> </body> </html>
4. console.log():- It is usually used for debugging purposes, you can also use the console.log() method in the browser to display content.
Example
<html> <body> <h1>crus4</h1> <script> console.log("Hey Developers!"); </script> </body> </html>