O'Reilly logo

JavaScript Absolute Beginner’s Guide by Kirupa Chinnathambi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

3. Functions

In This Chapter

Learn how functions help you better organize and group your code

Understand how functions make your code reusable

Discover the importance of function arguments and how to use them

So far, all of the code we’ve written contained virtually no structure. It was just...there:

alert("hello, world!");

There is nothing wrong with having code like this. This is especially true if your code is made up of a single statement. Most of the time, though, that will never be the case. Your code will rarely be this simple when you are using JavaScript in the real world for real-worldy things.

To highlight this, let’s say we want to display the distance something has traveled (see Figure 3.1).

FIGURE 3.1 The distance something ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required