Skip to main content

Arrow Functions / Lambda Expressions

Arrow Functions or Lambda expressions were introduced in ES6. Almost every modern language like C#, Java etc. have this feature. In very simple language we can say that Arrow functions are the expressions that help us to define functions and assign them to a variable. Let's try to understand the Arrow functions with the following example:
//With no argument   
 var firstFunc = ()=> {  
      console.log("This is a demo of Arrow functions / Lambda Expressions")  
 }  
 firstFunc();  
 
//With one argument  
 var secondFunc = (a) => { return a*100 }  
 console.log(secondFunc(20));  
 
//With Two Arguments  
 var thirdFunc = (a,b) => {  
      return (a+b)  
 }  
 console.log(thirdFunc(10,90));  
The above example create three arrow functions with one argument, two arguments and without any arguments. The out of the program will be:
 This is a demo of Arrow functions / Lambda Expressions  
 2000  
 100  
For personalized coaching, contact: dhandrohit@gmail.com
Happy Coding!

Comments