O'Reilly logo

JavaScript For Kids For Dummies by Eva Holland, Chris Minnick

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

Chapter 12

Making It Functional

Functions are the building blocks of JavaScript programs. They help you to keep from having to repeat yourself, and they make your programs neater and more flexible!

In this chapter, we use functions to create a game called Function Junction.

image

Understanding Functions

Functions are programs inside of programs. Functions are great at handling tasks that may be required multiple times by different parts of a program. They’re also a great way to keep things organized within your program.

Built-in functions

Some functions are built into JavaScript, such as the methods of arrays, strings, numbers, and other objects. You can tell that something’s a function because it has parentheses after it.

When a function is part of an object (such as the document object, for example) we call it a method. But it’s still a function.

Here are some of the functions that are built into JavaScript that you’ve already used:

getElementById()

toString()

addEventListener()

indexOf()

Can you think of other functions you’ve seen?

Custom functions

In addition to the functions that are built into JavaScript, you can also create your own, using the steps and information that we’re about to show you!

remember You can’t spell function without “fun,” and you can’t write JavaScript ...

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