JavaScript can show output in several places depending on what you are building and who the output is for (user or developer).
innerHTML / innerTextdocument.write()window.alert()console.log()innerHTML and innerText change the content of existing elements on the page.document.write() writes directly to the HTML while the page is loading.window.alert() shows a modal dialog that the user must dismiss.console.log() prints messages in the browser console (great for debugging).Both are used with document.getElementById() (or other DOM selectors) to change the content of an element.
innerHTML can insert HTML tags and text.innerText inserts only plain text.Writes raw HTML into the document while the page is loading. Using it after the page has loaded can replace the whole page content, so it is rarely used in modern code.
Displays a popup box with a message and an OK button. It pauses JavaScript execution until the user closes the dialog.
Sends text and values to the browser console (press F12 → Console). This is the preferred way to debug JavaScript code.
Set the content of a paragraph using innerHTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>innerHTML Example</title>
</head>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
</body>
</html>
Write content to the document while the page is loading
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>document.write Example</title>
</head>
<body>
<script>
document.write("This is written using document.write()");
</script>
</body>
</html>
Display a popup alert to the user
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Alert Example</title>
</head>
<body>
<script>
window.alert("This is an alert message!");
</script>
</body>
</html>
Log a message to the browser console for debugging
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>console.log Example</title>
</head>
<body>
<script>
console.log("This is logged to the console");
</script>
</body>
</html>
Use the buttons below to quickly see how different kinds of output behave. Open your browser console to see the console output.
DOM Output Updates this text area using innerHTML.
Click a button to update this text.
? Note: document.write() is not used here because calling it after a page has fully loaded can overwrite the whole page.
Your selected method output will appear here (except console).
console.log() for debugging instead of spamming users with alerts.innerHTML (or innerText) to update webpage content dynamically.document.write() after the page load; it can clear your entire document.document.getElementById() to avoid null errors.alert() for important user notices, confirmations, or critical warnings.alert().innerHTML when a button is pressed.console.log().document.write() during page load to print a welcome message (test it in a small, separate HTML file).innerHTML and innerText and observe how they handle HTML tags differently.