Functions Explained Very Simply

Basic ideas for beginners

1. What is a Function?

A function is like a machine.

You put something in → the function works → you get something out

Example:
Input: 2 → Output: 3

2. Functions First Worked Only With Numbers

At first, functions were used only with numbers.

Example:
A function takes 5 and returns 6.

So functions were seen as number machines.

3. Functions Can Work With More Than Numbers

Later, people realised something important.

A function does not need to work only with numbers.

A function can take:

And the result does not have to be a number.

4. Functions That Take Objects

An object is just a thing.

Examples of objects:

Example: A function that adds 1
Input: 2 → Output: 3

This kind of function works directly on objects.

5. Functions That Take Other Functions

Some functions do not take things.

They take other functions as input.

One function says: “Use this function twice”

This function does not care about numbers or objects. It only cares about another function.

6. Do Not Mix the Wrong Things

Functions expect the right kind of input.

Mixing the wrong things causes errors.

7. Simple Levels of Functions

To avoid confusion, functions are grouped by levels.

Level 1: Functions that take objects
Level 2: Functions that take other functions

This keeps everything clear and safe.

8. Programs Are Also Functions

A computer program is a special kind of function.

Input → Program → Output

Some programs take data. Some programs take other programs. Some programs return new programs.

The Big Idea

Some functions work on things.
Some functions work on other functions.
Always give the right input.