JavaScript can show data in several ways.
| Method | Where the output goes |
|---|---|
console.log() |
the browser console (F12) — for debugging |
element.textContent |
inside an HTML element, as plain text |
element.innerHTML |
inside an HTML element, as HTML |
alert() |
a pop-up box |
document.write() |
writes into the page while loading (avoid) |
Open the console
Press F12 (or Ctrl+Shift+J) and click the Console tab. console.log is the most used tool for checking values while you code.
textContent vs innerHTML
Use textContent for plain text — it is safer. Use innerHTML only when you need to insert HTML tags.
Example
Example — Different output methods
HTML
<p id="a"></p>
<p id="b"></p>
<script>
document.getElementById('a').textContent = '<b>textContent</b> shows tags as text';
document.getElementById('b').innerHTML = '<b>innerHTML</b> renders the tags';
console.log('Open the console (F12) to see this message');
</script>