LOGIC PROCESSING
Functions are the factories of your code. They take raw materials (parameters), process them using logic, and deliver a finished product (return value).
VISUAL_PIPELINE
Input
Also called Parameters or Arguments. This is the data you feed into the function to be processed.
Logic
The code inside the function body { ... }. It defines what happens to the input (math, formatting, logic).
Output
The Return Value. This is the final result that the function gives back to the rest of your program.
01. SYNTAX_BLUEPRINTS
LEGACYFunction Declaration
function calculateArea(width, height) {
return width * height;
}The traditional way. Hoisted (can be used before definition).
MODERNArrow Function
const calculateArea = (width, height) => {
return width * height;
};Concise syntax. Great for one-liners and callbacks.
02. ARROW_OPTIMIZATIONS
Implicit Return
const double = x => x * 2;
If the function body is a single expression, you can omit the {} and return keyword.
Single Parameter
const greet = name => console.log(name);
If there is exactly one parameter, you can omit the parentheses ().
Lexical 'this'
this. They inherit it from the parent scope.Perfect for callbacks and event listeners where context matters.
03. SCOPE_ANALYSIS
Global Scope (The Factory Floor)
Variables defined outside any function are Global. They can be accessed from anywhere in the code.
Local Scope (The Secure Room)
Variables defined inside a function are Local. They cannot be seen or used outside that function.
const secretKey = "12345"; // Only visible here
}