05. Three ways to print

Before we move on, let's look at the three ways we can print out some output. This will be helpful for you to use when trying to understand what is going on when your JavaScript is processes.

Writing out as an alert

An alert window is a small window popup. We can display text on it with the alert() command.

Writing onto document

To write onto our document (or within the browser), we use the document.write() function. We'll learn all about the document object in an upcoming lesson.

Writing out to console

Every browser has a JavaScript console. In Chrome, for example, you can access it by going to View, Developer, JavaScript console. To write out onto this console, use console.log().

Thus, we have three ways to output text:

alert("Hello world!");
document.write("Hello world!");
console.log("Hello world!");

As you go through this tutorial, it's important to try out what you learned on your own, and use one of the three ways to check your outputs.

Aching back from coding all day?

Prism Glasses

Aching back from coding all day? Try Back Problems

Ever feel achy from sitting crunched up on your computer table? Try lying down with these optical glasses that allow you to work on your laptop while lying flat on your back. This is the perfect solution with those with limited mobility or those who wish to prevent neck cramps and back strains.

$ Check price
4.454.45Amazon 4 logo(128+ reviews)

More Back Problems resources

Build modern and responsive webpages

HTML & CSS

Build modern and responsive webpages Try Front-end

This book teaches HTML as if it's for anyone - hobbyists, students, and professionals - and it's full-color throughout. It utilizes information graphics and lifestyle photography to explain the topics in a simple way that is engaging. You can progress through the chapters from beginning to end or just dip into topics of particular interest at your leisure.

$ Check price
29.9929.99Amazon 4.5 logo(926+ reviews)

More Front-end resources

Ad