FrontEnd Milestone Progress 60 %
Lesson : Function in JavaScript
Introduction to Functions
Definition: Reusable block of code for specific tasks.
Advantages:
Code Reusability: Use functions multiple times.
Less Coding: Avoid repetitive logic (DRY principle).
2. Function Declaration and Invoking
Declaration: Use the function keyword, name the function, and write logic inside {}.
Invocation: Call the function by its name with ().
3. Function with Parameters
Parameters: Listed in the function definition.
Arguments: Values passed during invocation.
Return Values: Use return to specify the output; without it, function returns undefined.
Function Types
Declaration: Named function, no variable assignment needed.
Expression: Can be anonymous, stored in a variable.
Parameter Handling
Single/Multiple Parameters: Pass as needed.
N Number of Parameters: Use arguments keyword.
Arrow Function
Introduced in ES6 for concise function writing.
Declaration
Syntax: const myFunction = (param1, param2) => { // logic code };
Call: myFunction();
Key Differences
Syntax: Arrow uses =>, traditional uses function.
Arguments: Arrow functions lack their own arguments object.
Recursive Function
Function that calls itself for problem-solving via subproblems.
Key Concepts Support
Base Case: Stops recursion, preventing infinite loops.
Recursive Case: Function calls itself until the base case is met.
Function Chaining
Call multiple functions sequentially on an object without intermediate variables.
Anonymous Function
Support