WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

JavaScript Output


JavaScript does NOT have any worked in print or show functions.


JavaScript Display Possibilities

JavaScript can "display" information in various ways:

  • Writing into an alarm box, utilizing window.alert().
  • Writing into the HTML yield utilizing document.write().
  • Writing into a HTML component, utilizing innerHTML.
  • Writing into the program comfort, utilizing console.log().

Using window.alert()

You can utilize an alarm box to show data:

Example

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<script>
window.alert(5 + 6);
</script>

</body>
</html>
Try it Yourself »

Using document.write()

For testing purposes, it is advantageous to utilize document.write():

Example

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<script>
document.write(5 + 6);
</script>

</body>
</html>
Try it Yourself »

Using document.write() after a HTML record is completely stacked, will delete all current HTML:

Example

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<button onclick="document.write(5 + 6)">Try it</button>

</body>
</html>
Try it Yourself »

Using innerHTML

To get to a HTML component, JavaScript can utilize the document.getElementById(id) strategy.

The id trait characterizes the HTML component. The innerHTML property characterizes the HTML content:

Example

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My First Paragraph</p>

<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>

</body>
</html>
Try it Yourself »

Using console.log()

In your program, you can utilize the console.log() strategy to show data.

Activate the program comfort with F12, and select "Console" in the menu.

Example

<!DOCTYPE html>
<html>
<body>

<h1>My First Web Page</h1>
<p>My first paragraph.</p>

<script>
console.log(5 + 6);
</script>

</body>
</html>
Try it Yourself »