Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

Web Development - JavaScript Output


JavaScript Output

There are several ways to display data in JavaScript. You can write it to the HTML page, show it in an alert box, or print it to the browser console.


Writing into HTML

You can display output directly inside an HTML element using document.getElementById().

Example

document.getElementById("demo").innerHTML = "Hello JavaScript!";
Try it Yourself »

This is the most common way to show results in a web page.


Writing into the Page

You can also write output directly to the HTML document using document.write().

Example

document.write("This text is written by JavaScript!");
Try it Yourself »

Note: Avoid using document.write() after the page has loaded, because it will overwrite the whole document.


Writing into the Console

For testing or debugging, you can write output to the browser console with console.log().

Example

console.log("Hello Console!");
Try it Yourself »

Open the browser's developer console (usually with F12) to see the output.


Showing Alerts

You can show small pop-up messages using window.alert().

Example

window.alert("Hello World!");
Try it Yourself »

This method is useful for simple messages, but not for real page output.


Summary

  • innerHTML - write into an HTML element.
  • document.write() - write into the document.
  • window.alert() - display an alert box.
  • console.log() - write to the browser console.

Next, you'll learn about JavaScript Syntax - the basic rules for writing JavaScript code.

Next » JavaScript Syntax


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.