Smal SEO Tool

JavaScript Output

JavaScript can "display" data in different ways:

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

Using innerHTML

To access an HTML element, JavaScript can use the document.getElementById(id) method.

html
document.getElementById("demo").innerHTML = 5 + 6;

Using document.write()

For testing purposes, it is convenient to use document.write().

html
<button onclick="document.write(5 + 6)">Try it</button>

Using window.alert()

You can use an alert box to display data.

javascript
window.alert(5 + 6);

Using console.log()

For debugging purposes, you can call the console.log() method in the browser to display data.

javascript
console.log(5 + 6);

Test Yourself with an Exercise

Which method is used to write to the browser's developer console?