Functions
Functions are reusable blocks of code. Instead of writing the same code over and over, you write it once inside a function and call it whenever you need it. Think of a function like a recipe: you write the steps once, then follow the recipe whenever you want to cook that dish. Key concepts: - Parameters are the inputs a function accepts - Return sends a value back to whoever called the function - Arrow functions are the modern preferred way to write functions
// Regular function
function greet(name) {
return "Hello, " + name + "!"
}
// Arrow function (modern, shorter)
const greet = (name) => "Hello, " + name + "!"
greet("Daniel") // "Hello, Daniel!"