English

Functions

Reusable Machines

A function is like a factory machine. You give it raw materials (inputs/arguments), it does some work, and hands you back a finished product (output/return value).

IN
⚙️
OUT

Real-world Examples

  • Juicer: Input (Apple) -> Output (Apple Juice)
  • Calculator: Input (5, 3) -> Output (8)

3 Core Concepts

1. Definition

Building the machine (writing the code inside the function).

2. Arguments

The inputs you pass to the machine when you use it.

3. Return Value

The final result the machine gives back to you.

Function Machine Simulator

Select a machine, provide inputs, and see what it returns!

Input 1 (x)
Input 2 (y)
Return Value (Output)
Waiting...
Under the Hood (Code)
function adder(x, y) {
  return x + y;
}\n// Usage
let result = adder(5, 3);

Quick Drill

Test your function knowledge!

Q: What is the data you pass into a function called?
Google AdSense Area