VERSIONS OF FUNCTION
There are 3 version of function are
NAMED Function
Anonymous Functions
3.Arrow Function
NAMED FUNCTION
Named Function is a function it has a own name to declare the function , it is easy to understand and reuse when the debug is occurred.
function greeting(name){
return "welcome" + name;
}
greeting(shobika);
output:
welcome shobika
Anonymous Functions
This function is does not defined the explicit name of the function , it is commonly used as a callback .
const greeting = function(name){
return "welcome" + name ;
}
greeting(ram);
output:
welcome ram.
ARROW FUNCTION
A new way to write functions using the => syntax. They are shorter and do not have their own this binding. it is the easiest way to write the function.
const greet= name=> "welcome" + name ;
console.log(greet("kumar"));
output:
welcome kumar
HOISTING
Hoisting in the JavaScript is when an output statement, variable declaration or a function calling in top of the scope is called a hoisting
console.log(i);
var i =10;
output:
undefined
SCOPE
There are 2 types of scope
Local Scope
Global Scope
In Local Scope there are a 2 type
Function Scope
Block Scope
BLOCK SCOPE FUNCTION SCOPE GLOBAL SCOPE
let let let
const const const
_ var var
Top comments (1)
The function stored in the
greetingvariable in your 'Anonymous Function' example is NOT anonymous - it has the name 'greeting'. The act of assigning an anonymous function to a variable ALSO assigns that variable's identifier as the name of the function. As the function in your example has a name, it is not anonymous. You can verify this by checkinggreeting.name- which will be 'greeting'.Most Developers Can't Answer This Question About Anonymous Functions ๐คฏ