READ: What is onclick Event?
1) Using innerHTML
This method is used to writing into an HTML element.
Use document.getElementById(id) method to access an HTML element.
The id attribute defines the HTML element and innerHTML property defines the HTML content.
innerHTML is a common way to display data in HTML.
2) Using document.write()
This method is used for writing into HTML output.
document.write() is very usefull for testing purposes.
Using document.write() after an HTML document is fully loaded will delete all existing HTML.
The document.write() method should only be used for testing purposes.
3) Using window.alert()
This method is used for writing into an alert box.
You can use an alert box to display data.
This type of output is usefull while displaying notice, confirmation etc.
4) Using console.log()
This method is used for writing into browser console.
console.log() method is used for debugging purposes.
Press F12 to display output.