0% found this document useful (0 votes)
12 views2 pages

JS 2

The document provides an overview of functions in JavaScript, covering their definitions, advantages, and types including declarations, expressions, and arrow functions. It explains parameters, return values, recursive functions, and function chaining. Key concepts such as code reusability and the DRY principle are highlighted throughout the lesson.

Uploaded by

Ashutosh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

JS 2

The document provides an overview of functions in JavaScript, covering their definitions, advantages, and types including declarations, expressions, and arrow functions. It explains parameters, return values, recursive functions, and function chaining. Key concepts such as code reusability and the DRY principle are highlighted throughout the lesson.

Uploaded by

Ashutosh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like