element.innerHTML / textContent: write into an HTML element.
console.log(): write to the browser console (press F12 to see it). Best for debugging.
window.alert(): show a popup box.
document.write(): writes directly into the page (only for testing).
The examples in this tutorial use a small log() helper that prints into the result pane, so you can see output without opening the console.
💡 Key Takeaways: JavaScript Output
Mastering JavaScript Output helps you write clean and reliable JavaScript code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
JavaScript Output Code Example
JavaScript
<pre id="out"></pre>
<script>
const log = (...a) => document.getElementById("out").textContent += a.join(" ") + "\n";
log("Hello from log()");
console.log("This one goes to the browser console (F12)");
document.body.insertAdjacentHTML("beforeend", "<h3>Written with insertAdjacentHTML</h3>");
</script>
<button onclick="alert('An alert box!')">Show alert</button>
Free sign-in required · Google login available
JavaScript Output Practice Exercises
Check what you learned in “JavaScript Output”.
/ 3 solved
Fill in the blank
Write a message to the browser console.
.log("Debugging...");
✓ Correct!Not quite. Try again.
Multiple choice
Which method shows a popup message box?
✓ Correct!Not quite. Try again.
Code challenge
Use log() to print the text Hello, Output!
Write the code in the live editor. Your answer is checked automatically.