JavaScript Functions
A function is a reusable recipe.
You write the steps once. Then you call the recipe whenever you need it.
Think of a cookie cutter. Same shape. Many cookies.
Function declaration
Parameters and return
Function expression
Arrow functions
Default parameters
Function declaration
Write function, then a name, then parentheses, then a block.
Parameters and arguments
Parameters are empty slots in the recipe.
Arguments are the real values you pass in.
Return
return sends a value back out.
After return, the function stops.
Function expression
You can store a function in a variable.
Arrow function
Arrow functions are a shorter style.
They are common for tiny helpers.
Default parameters
You can give a fallback value if no argument arrives.
Tip: Keep functions small. One clear job per function is easier to test and reuse.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.