Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

⚡ Functions in JavaScript ?

Uploaded by

developerram911
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

⚡ Functions in JavaScript ?

Uploaded by

developerram911
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

Functions In JavaScript

Function In JavaScript
A function in JavaScript is a reusable block of code designed to
perform a specific task. Functions allow you to encapsulate a
series of instructions that can be executed whenever they are
called, promoting code modularity, readability, and reusability.
Different Types Of Function Variant
1. Take Nothing Return Nothing

2. Take Something Return Nothing


3. Take Something Return Something

4. Take Nothing Return Something


Function Argument & Parameter
An argument is the actual value supplied to the function when
it is invoked (called). Arguments are the data that replace the
function parameters during execution.
A parameter is a variable defined in a function declaration or
expression. Parameters act as placeholders for the values the
function will receive when it is called.
Fat Arrow Function In Javascript
An arrow function in JavaScript is a concise way to write
anonymous functions, also known as lambda functions or fat
arrow functions. They were introduced in ECMAScript 6 (ES6)
and provide a more concise syntax compared to traditional
function expressions. Arrow functions are often used for
defining small, single-expression functions.
Anonymous Function
It is a function that does not have any name associated with it.
In anonymous functions, we use only the function keyword
without the function name.
Self-Executing Function / Immediate Invoked Function
The self-executing anonymous function is a special function
that is invoked right after it is defined. There is no need to call
this function anywhere in the script.
setTimeout & clearTimeout Function
setTimeout is a function in JavaScript used to delay the
execution of a function or a piece of code.
clearTimeout is a function used to cancel a timeout set by
setTimeout. It takes the unique identifier (ID) returned by
setTimeout as its argument.
setInterval Function & clearInterval Function
setInterval is a function in JavaScript used to repeatedly
execute a function or a piece of code at specified intervals.
clearInterval is a function used to cancel a recurring action that
was set up using setInterval.
Higher Order Function
In JavaScript, a higher-order function is a function that either
takes one or more functions as arguments, returns a function,
or both. Higher-order functions are a fundamental concept in
functional programming and allow for more flexible and
concise code.
1. Function As Argument
2. Function That Returns Function

3. Map, Filter, Reduce, forEach Concept


First Order Function
A First Order Function is just a normal regular function that
does not take any function as one of its parameters and also it
does not return another function as its return value inside its
body.
Variadic Function
A JavaScript variadic function is a function that can accept any
number of arguments. In variadic functions no predefined
number of function arguments is present that’s why a function
can take any number of arguments.
Pure Function
A pure function is a function that always produces the same
output for the same input. Has no side effects. This means it
does not alter any external state, such as modifying variables,
or object properties, or performing I/O operations (e.g.,
logging to the console, making HTTP requests).
Impure Function
An impure function is a function that May produce different
outputs for the same input due to relying on external states or
random values. Has side effects. This means it interacts with or
modifies the external state.
Currying In JavaScript
Currying is a functional programming technique in JavaScript
where a function is transformed into a series of functions, each
taking a single argument. This transformation allows for the
creation of more specialized and reusable functions.
Memorization In JavaScript
In JavaScript, Memoization is a programming technique used
to improve the performance of functions by caching their
previously computed results. When a memoized function is
called with the same arguments, the cached result is returned
instead of recomputing the result.
Thunk In JavaScript
A thunk is a function that returns another function. This can be
useful for controlling the execution of a piece of code,
especially when dealing with side effects like API calls or
complex calculations.

Tail Recursion In JavaScript


Tail recursion is a special form of recursion where the recursive
call is the last thing executed by the function. In other words,
the result of the recursive call is returned directly without any
further computation.
Generator Function
A generator function is a function that can yield multiple
values one at a time, pausing its execution and resuming later
from where it left off. It returns a generator object, which is an
iterator. They are defined using the function* syntax and use
the yield keyword to pause execution.
Recursive Function
Recursive functions in JavaScript are functions that call
themselves until a certain condition is met, often used for
tasks that can be divided into similar subtasks. A recursive
function is a function that calls itself to solve a problem. It
typically has a base case to stop the recursion and a recursive
case that reduces the problem size at each step.
First Class Function
In JavaScript, functions are first-class citizens, which means
they can be treated like any other value. This allows you to
assign functions to variables, pass them as arguments to other
functions, return them from other functions, and store them in
data structures.
1. Assigned To A Variable

2. Passed As An Argument
3. Return From Other Functions

4. Stored In Data Structure


Callback Function
A callback is a function passed as an argument to another
function. This technique allows a function to call another
function. A callback function can run after another function
has finished.
Callback Hell
Callback hell, also known as the "Pyramid of Doom," refers to
the situation that arises in asynchronous JavaScript
programming when callbacks are nested within callbacks
within callbacks, making the code difficult to read, understand,
and maintain.
THE END

You might also like