What are Functions?


A function is a block of code that performs a specific task and can be used again and again in a program.

Instead of writing the same code multiple times, you can place it inside a function and simply call that function whenever you need it.

Functions make programs shorter, cleaner, and easier to understand. They also help developers organize code in a professional way.

Why Functions Are Important

  • They reduce repeated code
  • They make programs easier to manage
  • They help organize logic clearly 
  • They improve code readability 
  • They allow reuse of the same logic  

Every real-world JavaScript application depends heavily on functions.

Here, the same message is written three times. If you want to change the message, you must update it in many places.

This shows why repeating code is not a good practice.

Now the message is written only once inside a function. The function is called three times to show the message.

If you want to change the message later, you only need to change it in one place.

This example shows how functions can accept data and perform actions based on that data.

By learning functions, students gain the ability to write clean, reusable, and professional JavaScript code — a key skill for becoming a job-ready developer.