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.

Build modern and responsive webpages

The Modern Web

Build modern and responsive webpages Try Front-end

The Modern Web will guide you through the most important tools of device-agnostic web development, including HTML5, CSS3, and JavaScript. The plain-english explanations and practical examples emphasize the techniques, principles, and practices that you'll need to easily transcend individual browser quirks and stay relevant as these technologies are updated.

$ Check price
34.9534.95Amazon 4.5 logo(30+ reviews)

More Front-end resources

Aching back from coding all day?

Self-Massage Tool

Aching back from coding all day? Try Back Problems

Relieve spasms, tight muscles, trigger points and pressure points with the Body Back Buddy! This trigger point massage is designed to help you self-message any area of your body - especially those that are hard to reach. Keeping your muscles relaxes and out of contraction is importan in helping to reduce pain and prevent muscle injury.

$ Check price
29.9529.95Amazon 4.5 logo(3,443+ reviews)

More Back Problems resources

Ad