Open In App

Arrow functions in JavaScript

What is Arrow Function ?

Arrow function {()=>} is concise way of writing JavaScript functions in shorter way. Arrow functions were introduced in the ES6 version. They make our code more structured and readable.

Arrow functions are anonymous functions i.e. functions without a name but they are often assigned to any variable. They are also called Lambda Functions.



Syntax:

const gfg = () => {
console.log( "Hi Geek!" );
}

The below examples show the working of the Arrow functions in JavaScript.



Arrow Function without Parameters




const gfg = () => {
    console.log( "Hi from GeekforGeeks!" );
}
  
gfg();

Output
Hi from GeekforGeeks!

Arrow Function with Parameters




const gfg = ( x, y, z ) => {
    console.log( x + y + z )
}
  
gfg( 10, 20, 30 );

Output
60

Arrow Function with Default Parameters




const gfg = ( x, y, z = 30 ) => {
    console.log( x + " " + y + " " + z);
}
  
gfg( 10, 20 );

Output
10 20 30

Arrow functions can be async by prefixing the expression with the async keyword.

async param => expression
async (param1, param2, ...paramN) => {
statements
}

Advantages of Arrow Functions

Limitations of Arrow Functions

Supported Browsers


Article Tags :