𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝘀 𝗘𝘅𝗽𝗹𝗮𝗶𝗻𝗲𝗱

Functions are blocks of code. They perform specific tasks. You write them once and use them many times.

Functions do nothing until you call them. Calling a function means you tell the computer to run that specific code block.

Why you need functions:

How a function works: Functions use the function keyword. You give the function a name. You use parentheses () to hold inputs. You use curly brackets {} to hold the code.

Input and Output:

You can store the result of a function in a variable.

Example: function add(a, b) { return a + b; }

let sum = add(5, 5);

Local Variables: Variables created inside a function stay inside that function. This is called local scope.

This keeps your code clean and prevents errors in other parts of your program.

Source: https://www.w3schools.com/js/js_function_intro.asp

Full post: https://dev.to/vidhya_murali_5aabe7784bd/functions-in-javascript-38h8