User Tools

Site Tools


programming:output_js

Output

There are a few way to output things in Javascript

window.alert():

window.alert will display text in a alert box when called. You can also forgo the window key word and just use alert.

Example:

window.alert(‘Hello World!’);
alert(“Hello again!);
alert(4+5); // this will show 9 in the box

console.log():

console.log will write directly to the Javascript console, and should only really be used for debugging. This will not affect the HTML or CSS at all when used.

This W3 article covers more about JavaScript debugging where to find the console on most major browsers : » W3 schools - debug «

Example:

Console.log(‘Hello world’);
Console.log(33);

document.write():

This method will write to the HTML document.

THIS WILL DELETE ALL HTML OF A LOADED HTML DOCUMENT AND SHOULD ONLY BE USED FOR TESTING

Example:

document.write(5 + 3);
document.write(‘<p> Hello world</p>’);

There are better ways to make changes to HTML and add CSS after a page has been loaded. This will be covered in the DOM article.

» W3 schools - JS DOM «

programming/output_js.txt · Last modified: 2020/10/02 20:38 by shapirofrosts