JavaScript Function, Expression, Scope, Hoisting, Closure.
Function: Simply said, a function is a type of machine that takes different data as input, processes the data on different logics, and gives output.
***The special advantage of the function is that it reduces code duplication.
Function Declarations :
Function invoking: Declaring a function does not execute immediately. The function for this is to call. And this call is called function invoking. In other words, using the function is function invoking.
IIFE: A js immediately invoked function expression(IIFE) is used if you need to call immediately after creating a function.
The Arguments Object: We do not know how many arguments the user will pass when calling the function, again the number of parameters to be given in the function is not fixed. To solve this problem there are argument objects. JS functions have a built-in object called the arguments of object. Change the arguments are not visible outside the function.
This means that I can access the arguments sent from outside by the argument keyword inside the function.
Function Expression: Expression means that evaluates to a single value from the valid set of literals, variables, operators. Like,5+ 5 =10. It is a simple expression that evaluates a single value of 10. But what is the Function Expression??
A function expression can be stored in a variable. Then you can call that variable and work.
Actually, this function is called the Anonymous function because it has no name. Here add is a variable but acts like a function. We know that Expressions always in a single value. And above function return a single value.
Scoping: Scope controls where a variable is declared and where it can be accessed. In js two types of scope:
- Local Scope- Each function creates a local scope. The variable declared in the local scope cannot be used outside that scope
- Global Scope- A Global variable has global Scope. Variables declared in Global Scope can be used in any scope. It can be used in a functional scope. But the variable declared in the local scope cannot be used outside that scope.
JS Hoisting: When to declare a variable, when to assign a value, when to reassign a value, when to use that variable. All of this is the job of hosting. Like, a variable can't be used after declared.
Functional Programming: The role of functional programming is to avoid shared state, mutable and side effects. When a function behaves like a value, it is called Functional Programming.
Get Mosharofhossen’s stories in your inbox
Join Medium for free to get updates from this writer.
there are three main terms……..
- Pure functions 2. First-class functions 3. Higher-order function
What is Pure Function?
- ** It returns the same result if given the same arguments
- **It does not cause any observable side effects
the above function is not a pure function because it modified a state point.x and point.y outside its scope.
it is a pure function. It didn't side effect the external state.
What is a First-class function?
- ** A function can be stored in a variable.
- ** A function can be stored in an array
- ** A function can be stored in an object
- ** We can create function as need
High Order function :
- ** We can pass a function as an argument.
- ** We can return function from another function.
Closure: If data comes from an outside scope inside a scope, then that scope is called its closure. (bahirer duniay thaka kono kichu ke carry kore/ variables that are used locally but defined in an enclosing scope)









