Three Different Methods of Java Script Output

By Edwin Axavier Santiago

Method One: console.log()

The first method is called "console.log()." It writes a messgae directly to the console. An example of it would be "console.log(Hello)"

Method Two: getElementById()

The second method is called "getElementById()." It returns the element ID atttribute with the specified vaule. It is the most common method in the HTML DOM, and is used almost every time you want to manipulate, or get info from, an element on your document. An example of this is "document.getElementById("demo");" If the element you specified can not be found it will returhn "null." Normaly an ID should be unique within a page. However, if more than one element with the specified ID exist, the "getElementByld()" method returns the first element in the source code.

Method Three: window.alert()

The third method is called "window.alert()." It displays an alert box with a specified message and an OK button. An alert box is used if you want to make sure iformation comes through to the user. Something to note is that an alert box will take away focus from the current window and force the browser to read the message. It is wise not to overuse this message as it prevents the user from accessing other parts of the page until the box is closed. An exmaple of this is "alert("Hello! I am an alert box!");

Check out my Java Script input!

Check out my welcome page!

Check out my event page!

Check out my 8ball!

Go back to home page!