It is always desired to display data on the webpages in various forms. JavaScript allows users to do the same in various forms.
The following method / properties are used to do so:
document.write() method is used to display the data onto the webpage. It is to remember that do not call document.write() method after the document has finished loading, if so it will overwrite the whole web document.
Code:
Output:
window.alert() method is used to display an alert box with specified data on the webpage. A small pop-up box with a closing button appears, and disappears after the button is clicked.
Code:
Output:
console.log() method is used to check whether the data in reaching upto the browser or not. This is mainly used for debugging purposes and the data is displayed only in debugging console mode. This mode can be activated by pressing F12 or through setting options.
Code:
Output:
document.getElementById(id) method of JavaScript is used to access an HTML element. The ‘id’ attribute in the method defines the HTML element. The Content / data to be displayed is specified with innerHTML property of document.getElementById() method.
Code:
innerHTML property
Output: