๐—๐—ฎ๐˜ƒ๐—ฎ๐—ฆ๐—ฐ๐—ฟ๐—ถ๐—ฝ๐˜ ๐—™๐˜‚๐—ป๐—ฐ๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐—˜๐˜…๐—ฝ๐—น๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฑ

Functions are reusable blocks of code. They perform specific tasks. Think of a function as a machine. You provide input. The machine processes it. It gives you an output.

Functions stop you from writing the same code over and over. If you need to print a message 100 times, you write one function instead of 100 lines of code.

Benefits of functions:

Naming your functions matters. Use names that describe the action.

Rules for names:

Key parts of a function:

Do not confuse parameters with arguments. Parameters are the placeholders. Arguments are the actual values you pass in.

Return vs Console.log: Many beginners mix these up.

Professional developers use return to keep code flexible.

Three ways to write functions:

  1. Function Declaration: function add(a, b) { return a + b; }
  2. Function Expression: const add = function(a, b) { return a + b; };
  3. Arrow Functions: const add = (a, b) => a + b;

Arrow functions are standard in modern frameworks like React.

Commonly used methods:

Break your large applications into small, manageable functions. It makes testing and fixing bugs much easier.

Source: https://www.geeksforgeeks.org/javascript/functions-in-javascript/ Source: https://www.w3schools.com/js/js_functions.asp

Full post: https://dev.to/dev_saravanan_journey/javascript-functions-explained-1706