JavaScript Output

1 year 5 months ago

We can "display" data using Javascript in following ways:

  • Write it in an HTML element, using innerHTML.
  • Write it in the HTML output using document.write().
  • Write it in an alert box, using window.alert().
  • Write it in the browser console, using console.log().

Javascript innerHTML

To 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:

Using document.write()

It is easy to use use document.write() for testing purposes. You actually directly write to your HTML element using document.write(). When you use document.write() it will completly replace with HTML document after fully load.

Using window.alert()

You can use an alert box to display data:

Use console.log() to display your data in console windows

It is easy to use the console.log() method to display data on console window for debugging purpose

Shahid Hussain

Shahid Hussain is a frontend developer and UX Consultant living and working in Sweden. Shahid is specializes in JavaScript development and developed anything from WordPress websites to complex e-commerce JavaScript applications. Shahid can also sketch, from websites to apps and icons, even print material. He works on content-centric, and mobile products, as well as cross-portal user experiences. Photography, music and travelling can trigger his attention.