Conditional function
Function can be declare in a conditional statement.
Recursive function
This is a function that call itself. Just for instance, looping with while
loop can run code for infinite number of times but when break
keyword is applied, it prevent such from happening, likewise recursive function can be infinite.
Using if
...else
statement ends infinite recursion.
Callback function
This is simply when an arguments is passed as a function call in another function.
with function expression
with more function expression
Array method runs as function
These are some array method like map, reduce, filter, slice ... are use as a function.
const number = [10, 20, 30, 40, 50];
//adding 100 to each value in number
const result = number.map(
(num) => num += 100
)
console.log(number); // [10, 20, 30, 40, 50]
console.log(result); // [110, 120, 130, 140, 150]
Review my article on all JavaScript method; array methods...
Click now 👆
Arguments in function call
It's when many argument are pass to a function along with a seperator like , ; : - _ using arguments[i]
; this simply means array of argument from 0 to any positive number.
It have a similarity in rest parameters. To get the total number of arguments passed use the keyword arguments.length
Rest parameters
This is when a function call many parameter with it parenthesis.
Nested function
Simply refer to as function in a function.
function divide(x) {
function value(y) {
return x / y;
}
return value;
}
console.log(divide(10)(5)); //2
With two parameter
It also form a closure, meaning the inner function(second function) can only be accessed with in the outer function and can make use of the arguments and variables of the outer function(first function) while outer function can not access variables or define function inside a inner function.
Function closure
These are inner function in a outer function.
without parameter
Function Curry
This is a sequence of function
that runs each containing a single parameter and then return many argument
.
It's function
that return other function
with single parameter each.
Function Composition
This is applying more than one function to a function call.
It's shows similarities to mathematical derivations in function.
Function Decorator
This is a function
that takes one function
as an argument and return that function
with variation of argument.
This is refers to as a design pattern, that wraps function in another function.
It can also be use in Class decorator and Class member decorators. It is deep in learning and widely used in TypeScript, for to be use in JavaScript needs some tools like Babel and TypeScript compiler.
Top comments (0)