JavaScript Output
There are different ways to get output in JavaScript is as following below:
-
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().
You can access an HTML element, JavaScript can use the document.getElementById(id) method.
The id attribute defines the HTML element. The innerHTML property defines the HTML content:
Example
Output
It is used for testing purposes, it is convenient to use document.write():
Never call document.write after the document has finished loading. It will overwrite the whole document.
Example
Output
You can use an alert box to display data:
Example
Output
Example
Output