JavaScript is a can “display” data in multiple ways:
Writing into an HTML a component, employing innerHTML.
Writing into the HTML output using document.write().
Writing into a warning box, use window.alert().
Writing into the viewer console, using console.log().
Using innerHTML
To get an HTML element, JavaScript can use the document.getElementById(id)method.
The id variable gives the HTML element. The innerHTML field provides the HTML content:
Example
My First Web Page
My First Paragraph
Changing an HTML element’s innerHTML attribute is a standard method for displaying data in HTML.
Using document.write()
For tests uses, it is simple to use document.write():
Example
My First Web Page
My first paragraph.
Example
------Example mukavu------
The document.write() method must only be used for development.
Using window.alert()
An alert box can be used to show data:
Example
My First Web Page
My first paragraph.
The windowkeyword need not be used.
The window object in JavaScript is an international scope object. This indicates that the window object is the usual owner of variables, properties, and methods. This implies that it’s not necessary to specify the windowkeyword:
Example
My First Web Page
My first paragraph.
Using console.log()
You can display data by calling the console.log() method in the browser for research purposes.
A later chapter will cover more about programming.
Example
JavaScript Print
There are no print methods or objects in JavaScript.
JavaScript does not allow you to access output devices.
The window can be called, but that’s just one limitation. To print the contents of the current window.print() method in your browser.