← JavaScript learning path
JavaScript · Module 5 of 10

Functions

Write reusable code with function declarations, arrow functions and parameters.

📖 Key ideas

  1. function add(a, b) { return a + b; } declares a function.
  2. Arrow functions are shorter: const add = (a, b) => a + b.
  3. Parameters can have defaults: (name = "Guest").
  4. Functions can be passed as values (callbacks).
  5. 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