Sunil Vishwakarma
@linkinsunil
Types of Functions
in JavaScript
first class higher order
function function
first order unary
function function
pure currying
function function
Explained
👉if this helped you, please like and share it
Sunil Vishwakarma 1
@linkinsunil
First Class Function
In Javascript, functions are first class objects.
First-class functions means when functions in that
language are treated like any other variable.
In such a language, a function
can be passed as an argument to other
functions,
can be returned by another function and
can be assigned as a value to a variable.
For example, in the below example, handler
function assigned to a listener.
swipe
Sunil Vishwakarma 2
@linkinsunil
Higher Order Function
Higher-order function is a function that accepts
another function as an argument or returns a
function as a return value or both.
swipe
Sunil Vishwakarma 3
@linkinsunil
First Order Function
First-order function is a function that doesn’t
accept another function as an argument and
doesn’t return a function as its return value.
swipe
Sunil Vishwakarma 4
@linkinsunil
Unary Function
Unary function (i.e. monadic) is a function that
accepts exactly one argument. It stands for a
single argument accepted by a function.
Let us take an example of unary function,
swipe
Sunil Vishwakarma 5
@linkinsunil
Pure Function
A Pure function is a function where the return
value is only determined by its arguments without
any side effects. i.e, If you call a function with the
same arguments 'n' number of times and 'n'
number of places in the application then it will
always return the same value.
Let's take an example to see the difference
between pure and impure functions,
swipe
Sunil Vishwakarma 6
@linkinsunil
Currying Function
Currying is the process of taking a function with
multiple arguments and turning it into a sequence
of functions each with only a single argument.
Currying is named after a mathematician Haskell
Curry. By applying currying, a n-ary function turns
it into a unary function.
Let's take an example of n-ary function and how
it turns into a currying function,
swipe
@linkinsunil