DEV Community

R.Shobika CSE
R.Shobika CSE

Posted on

FUNCTIONS OF JS PART -2

VERSIONS OF FUNCTION

There are 3 version of function are

  1. NAMED Function

  2. 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);
Enter fullscreen mode Exit fullscreen mode

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);
Enter fullscreen mode Exit fullscreen mode

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"));

Enter fullscreen mode Exit fullscreen mode

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;
Enter fullscreen mode Exit fullscreen mode

output:
undefined

SCOPE
There are 2 types of scope

  1. Local Scope

  2. 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
Enter fullscreen mode Exit fullscreen mode

Top comments (1)

Collapse
 
jonrandy profile image
Jon Randy ๐ŸŽ–๏ธ

The function stored in the greeting variable 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 checking greeting.name - which will be 'greeting'.