JavaScript Output

JavaScript Output


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().
  • Getting output in JavaScript with the help of Using innerHTML.
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
  • Getting output in JavaScript with the help using document.write().
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
  • Getting output in JavaScript with the help Using window.alert()
You can use an alert box to display data:
Example
Output
  • Getting output in JavaScript with the help using console.log()
Example
Output