A function is a reusable block of code that performs a specific task. A function is a reusable block of code that performs a specific task. Instead of writing the same code multiple times, you write it once inside a function and call it whenever you need it.