FUNCTION
BASIC FUNCTION SYNTAX
function f.name(parameter)
{
}
EVERY TIME WE NEED TO CALL/INVOKE THE FUNCTION
console.log / return inside function
Console.log(a+b) will display the output directly
If u want to use the output of this function as data for other line u need to use return .
If we use both it will print console and log immediately and store the return value in the variable
return RELATED PROBLEMS
PROBLEM 1
PROBLEM 2
If Parameter Count < Argument Count then the remaining parameters are consider as undefined
If Parameter
Count > Argument Count then the
remaining parameters are omitted
Because of this Function Overloading is not possible in JavaScript
FUNCTION OVERLOADING
function add (a,b,c)
function add (inta,intb)
function add (inta,intb)
In above case if user gives only two inputs a, b then automatically JavaScript take value c as undefined and automatically execute the first add thats why Function Over Loading is not possible in JavaScript
DEFAULT
PARAMETER
In javascript we can able to set only the last parameter as default parameter we can’t set first or middle parameter as default parameter.
ANONYMOUS FUNCTION
Function without name and passed inside the variable.To call this function we need to call the variable
IIFE - Immediately Invoked Functional Expression
IIFE functions are wraped and called immediately .These kind of functions are called only once.
INLINE
FUNCTION
When we declare a function
inside a function we can’t call that inside function alone in program those
kind of functions are called as inline function.
In the above example we can't call the function add separately this is called as inline function
CALL BACK FUNCTION
When you are calling outside function inside any other function is called call back. Passing function into the function
EXAMPLE PROB FOR CALL BACK FUNCTION
Write 4 different functions add,sub,mul and div.And put all function inside array
var operator = [add,sub,mul,div]; and then write a function maths
function maths(ind,arr)
{
val1 =5;
val2 = 10
(write code to call add,sub,mul,div)
}
SOLUTION
https://day9-callback.netlify.app/
ARRAY METHODS YOUTUBE VIDEO
Comments
Post a Comment