1. Computing & Technology

3. Functions

An introduction to using functions with JavaScript.

Introduction to Functions

The simplest way to set up reusable code in JavaScript is using Functions.

How to Call a Function

The way you call a function is slightly different from the way you reference variables.

Same Function Different Variables

If you define arguments for your function then you can pass different variables as parameters for each call.

Optional Parameters

JavaScript allows you to pass different numbers of parameters to your function at different times.

The Scope of Variables

Variables inside a function may not exist outside of it.

Returning a Value

Functions can have a value that they return back into the code they were called from.

Function Libraries

Writing your own library of functions or using such a library written by others will make writing JavaScripts faster.

©2012 About.com. All rights reserved.

A part of The New York Times Company.