JAVASCRIPT OUTPUT

JSWe introduce the “Output in Javascript” argument by saying that JavaScript can “display” data in several ways:

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

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.

Copy to Clipboard

OUTPUT IN JAVASCRIPT THE METHOD DOCUMENT.WRITE

For testing purposes, it is convenient to use document.write().

Using document.write () after loading an HTML document will delete all existing HTML.

OUTPUT IN JAVASCRIPT WINDOW.ALERT

You can skip the window keyword. In JavaScript, the window object is the global scope object, which means that variables, properties and methods by default belong to that object. This also means that specifying the window keyword is optional:

CONSOLE.LOG

For debugging purposes, you can call the console.log() method in your browser to view the data. You will learn more about debugging in a later post.

Console
Copy to Clipboard

LINKS TO PREVIOUS POST

THE JAVASCRIPT LANGUAGE

LINK TO THE CODE ON GITHUB

GITHUB