Pure Functions :
Pure Functions :
Mutating : Changing the Value
function getDoubleValue(number){ //Pure functions program
return number * 2;
}
const result = getDoubleValue(225250);
console.log(result);
OP : 450500
Impure Functions :
const x=4; //this is impure function due to it depends upon outer parameter
function getDoubleValue(number){ //imPure functions program
return number * 2 * x;
}
const result = getDoubleValue(225250);
console.log(result);
Imp : A Pure Function is a Function which Does Everything Internally
Append Numbers :
function appendNumbers(arr){ //appendNumbers Using pure funcitons
let newArr = [];
newArr.push(...arr, 5,6);
return newArr;
}
const result = appendNumbers([1,2,3,4]);
console.log(result);
Key Points : When you are writing functions, try to write with in, not from outer prameters!
First Class Functions :
a programming language is said to have first class functions in that language are treated like other variables so the functions can be assigned to any other variable or passed as an argument or can be returned by another function.
It means that functions in JavaScript have the same status as other data types like strings, numbers, or objects. Functions can be:
Method : 1