</> Code Corner

JavaScript · JS Tutorial · Lesson 3

JS Output

innerHTML, document.write, alert and console.log.

JavaScript can "display" data in different ways:

  • Writing into an HTML element, using innerHTML or innerText
  • Writing into the HTML output using document.write()
  • Writing into an alert box, using window.alert()
  • Writing into the browser console, using console.log()

Example

<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
console.log("This goes to the developer console");
</script>
Tip: Using document.write() after the page has loaded deletes all existing HTML. Use it only for testing.

Keep reading “JS Output”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋