Concept Flow - Arrow functions
Start
Define arrow function
Call arrow function
Execute function body
Return result
End
This flow shows how an arrow function is defined, called, executed, and returns a result.
const add = (a, b) => a + b; const result = add(2, 3); console.log(result);
| Step | Action | Evaluation | Result |
|---|---|---|---|
| 1 | Define arrow function 'add' | const add = (a, b) => a + b; | Function 'add' created |
| 2 | Call 'add' with arguments 2 and 3 | add(2, 3) | Function body executes with a=2, b=3 |
| 3 | Calculate a + b | 2 + 3 | 5 |
| 4 | Return result from function | return 5 | 5 |
| 5 | Assign returned value to 'result' | result = 5 | result is 5 |
| 6 | Print 'result' to console | console.log(result) | Output: 5 |
| Variable | Start | After Step 2 | After Step 5 | Final |
|---|---|---|---|---|
| add | undefined | function (a, b) => a + b | function (a, b) => a + b | function (a, b) => a + b |
| result | undefined | undefined | 5 | 5 |
Arrow functions use a short syntax: (params) => expression They automatically return the expression value if no braces are used. No 'function' keyword needed. Useful for concise functions. Example: const add = (a, b) => a + b;