# Function

URL: https://softwaredictionary.org/terms/function
Category: Programming Fundamentals
Last updated: 2026-09-29
In Turkish: Fonksiyon

In short: A function is a named, reusable block of code that performs a specific task, optionally taking inputs called parameters and returning a result.

## What is a function?

A function packages a set of instructions under a name so you can run them whenever you need them, just by calling that name. It can accept inputs, called parameters, and send back an output, called a return value. Functions are one of the most basic building blocks of almost every programming language.

A kitchen blender is a good analogy for a function. You put ingredients in (the arguments), press the button (call the function), and get a smoothie out (the return value). You don't need to think about how the motor works each time; you just use it.

Functions help you avoid repeating code, break big problems into smaller pieces, and test each piece on its own. A good function usually does one clear job and has a descriptive name like `calculateTotal` or `sendEmail`. In languages like JavaScript, functions are also values: they can be stored in variables, passed to other functions, and returned from them.

A method is a function that belongs to an object or class, such as `user.save()` in object-oriented code. Parameters and arguments are also often mixed up: parameters are the names listed in the function definition, while arguments are the actual values passed in when the function is called.

## Key takeaways

- A function is a reusable, named block of code that does one job.
- Parameters are the inputs a function declares; arguments are the values you pass in.
- A `return` statement sends a result back to the caller.
- A method is a function attached to an object or class.

## Example: Defining and calling a function

```javascript
// Define a function with two parameters
function calculateTotal(price, taxRate) {
  const tax = price * taxRate;
  return price + tax; // send the result back to the caller
}

// Call it with two arguments
const total = calculateTotal(100, 0.2);
console.log(total); // 120

// Arrow function: a shorter syntax for the same idea
const double = (n) => n * 2;
```

## Frequently asked questions

**What is the difference between a function and a method?**

A method is a function that is attached to an object or class and is called through it, like `list.push(4)`. A plain function stands on its own and is called directly, like `calculateTotal(100, 0.2)`.

**What is the difference between parameters and arguments?**

Parameters are the variable names listed in a function's definition. Arguments are the actual values you supply when you call the function.

**What is a pure function?**

A pure function always returns the same output for the same input and has no side effects, such as changing global variables or writing to a file. Pure functions are easier to test and reason about.

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
