agyanadda@gmail.com

JS Output

JavaScript Basics 1 min read Updated Dec 1, 2026 Topic 3 of 38

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>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which method writes a message to the browser console?

Exercise 2 True / False

textContent renders HTML tags.

Exercise 3 Fill in the Blank

Press ___ to open the browser developer tools.

Frequently Asked Questions

If it runs after the page has loaded, it erases the whole page. Use textContent or innerHTML instead.