What Is a Function in Code?
When people start learning about code, one word shows up again and again: function. It sounds technical, but the idea behind it is simple and friendly. Let's take the mystery out of it together. 🔦
A function is a small, reusable piece of instructions. You give it something to work with, it does its job, and it hands something back. That's the whole shape of it: input goes in, output comes out.
The blender on your kitchen counter
Picture a blender. You drop in fruit, press the button, and a smoothie pours out.
The blender doesn't care which fruit you use. Strawberries today, mango tomorrow — same machine, same button, different result each time. You don't rebuild the blender for every snack. You just feed it new ingredients and let it do the work.
A function in code works exactly like that blender.
- The fruit you put in is the input (programmers call this an "argument").
- The blending is the work the function does inside, hidden from view.
- The smoothie that comes out is the output (programmers call this the "return value").
You built the blender once. After that, you use it over and over. That "build once, use many times" idea is the heart of why functions exist.
A tiny example in words
Imagine a function whose job is to double a number. We could call it double.
- You hand it
4. It gives back8. - You hand it
10. It gives back20. - You hand it
7. It gives back14.
Same machine every time. You never had to explain how to double a number more than once — you taught it the rule a single time, then just kept feeding it new numbers.
That's the quiet superpower of functions: you describe a task once, give it a name, and then reuse it whenever you need it.
Why coders love them so much
Three reasons, all very human:
Less repeating yourself. Without functions, you'd rewrite the same instructions every single time you needed them. With a function, you write the recipe once and call it by name.
Fewer mistakes. If the instructions live in one place, you only have to fix a problem once. Imagine if every blender in your house had to be repaired separately — one shared blender is far easier to keep working.
Easier to read. A name like double or sendWelcomeEmail tells you what's happening at a glance. You don't have to read every line inside to understand the point — the same way "blend" tells you enough without explaining the motor.
The one sentence to remember
A function is a named, reusable little machine: you put something in, it does its job, and it gives something back.
Once that clicks, a huge amount of code starts to make sense. Programs are mostly just lots of little machines, each with a clear job, passing their results to one another — like a kitchen full of helpful gadgets working together.
You've just learned one of the most important building blocks in all of programming, and you did it without writing a single line of code. That curiosity you're feeling right now? Keep following it. The next idea will feel a little easier than this one did, and the one after that easier still. One small machine at a time. 🐙
Keep going with Pip
Ready to write your first real code? Pip's Programming, from Zero course starts at the very beginning — one friendly lesson at a time.
Take Pip's Programming, from Zero course →