A function is a reusable block of code that performs a specific task. Instead of writing the same code over and over in different parts of your program, you write it once inside a function and then call it whenever you need it.
Functions can accept parameters — values you pass in for the function to work with. They can also return a value back to wherever they were called from. A function that doesn't return anything simply performs its task and finishes.
Keeping functions small and focused on a single task is considered good practice across all languages. Well named functions also make your code much easier to read — a function called calculateScore() tells you exactly what it does without needing to read the code inside it.