JavaScript - Output

JavaScript Output

JavaScript can be displayed data using the following methods or ways:

  • innerHTML
  • document.write()
  • window.alert()
  • console.log()
  • window.print()

innerHTML

It uses the document.getElementById(id) method together with the innerHTML to display content for that HTML; that has the specific id attribute value.

document.write()

This JavaScript method of outputting data is often used for testing purposes.

note
NOTE:

Do not use document.write() after the HTML document is loaded; it will delete all existing HTML contents.


window.alert()

This method is used to display a pop-up alert box containing some data.

tips
TIP:

The window keyword can be skipped in window.alert() to become just alert(). The reason is because the window object is a global scope object.

console.log()

This JavaScript method of outputting data is used for debugging purposes.

  • To open your console from your browser, Press F12 then select console

window.print()

This JavaScript method use to print the current data in that page.

ADVERTISEMENTS

LEARNING IS A CONTINOUS PROCESS - PRACTICE MAKES PERFECT