How to Display using JavaScript

JavaScript can display data in many ways.

  1. Writing into an HTML element - innerHTML
  2. Writing into the HTML output - document.write()
  3. Writing into an alert box - window.alert()
  4. Writing into the browser console - console.log()

To access an HTML element,you can use the document.getElementById(id) method. The id attribute defines the HTML element. The innerHTML property defines the HTML content. For example,

var element = document.getElementById('demo')
element.innerHTML = 'Hello World!';

The document.write() method should only be used for testing.

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