← JavaScript learning pathJavaScript · Module 5 of 10
Functions
Write reusable code with function declarations, arrow functions and parameters.
📖 Key ideas
- function add(a, b) { return a + b; } declares a function.
- Arrow functions are shorter: const add = (a, b) => a + b.
- Parameters can have defaults: (name = "Guest").
- Functions can be passed as values (callbacks).
- A function without return gives undefined.
💡 Real-life example: A function is a recipe card: write it once, cook it whenever you need, with different ingredients.
returnSends a value back to the caller
Arrow functionShort syntax (a, b) => a + b
CallbackFunction passed to another function
Default parameterValue used when an argument is missing