Technology Fundamentals

Function

Definition

A function is a reusable block of code that performs a specific task. It can take inputs (called parameters or arguments) and can return an output value.

Why It Matters

Functions are a core principle of "Don't Repeat Yourself" (DRY) programming. They allow you to organize code into logical, reusable blocks, making programs easier to write, test, and debug.

Contextual Example

You could write a function `calculateArea(width, height)` that takes two numbers as input, multiplies them, and returns the result. You can then call this function anywhere you need to calculate the area of a rectangle.

Common Misunderstandings

  • In some contexts, functions are also called methods, subroutines, or procedures.
  • Declaring a function just defines what it does; you must "call" or "invoke" the function to actually execute its code.

Related Terms

Last Updated: December 17, 2025