Thursday, November 20, 2025
HomeLanguagesJavascriptLambda Expressions in JavaScript

Lambda Expressions in JavaScript

A lambda expression is a code you enter to define a short function. A lambda function is mostly present in modern languages (Ruby, Javascript, Java..). It’s just an expression that creates a function. 

It is very important that programming languages ​​support first-class functions, which natively pass functions as arguments to other functions or assign them to variables. This is source code text passed to the compiler and recognized using a specific syntax. (In Javascript, this is technically called an arrow function expression/declaration.) At runtime, the expression is evaluated as a lambda function in memory.

A lambda function is a short and anonymous function that takes one or more parameters and contains a single expression. Basically, you can pass a function as a parameter to another function. Because functions are treated as objects in JavaScript, they can be passed to and returned from other functions to create lambda functions.

 

Advantages of Javascript Lambda Functions:

  1. Lambda functions are pure functions in Javascript.
  2. Lambda functions are easy to read.
  3. Lambda functions are easy to cache.

Syntax:

function(arg1, arg2...argn) expression

 

Example 1: In this example, the arrow function is used for showing lambda expression.

Javascript




let multiply = (a, b) => a * b;
console.log(multiply(5, 9));


Output:

45

In this example, the arrow function is used and we have taken two parameters and have a single expression.

Example 2: In this example, an anonymous function is used which shows the lambda expression.

Javascript




const Names = [
  'Mansi',
  'Gaurav',
  'Akansha',
  'Sanya'
];
  
console.log(Names.map(Names => Names.length));


Output:

[ 5, 6, 7, 5 ]

In this example, an anonymous function is created which makes the code small and returns the length of Names in the array.

RELATED ARTICLES

Most Popular

Dominic
32405 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6778 POSTS0 COMMENTS
Nicole Veronica
11927 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11995 POSTS0 COMMENTS
Shaida Kate Naidoo
6905 POSTS0 COMMENTS
Ted Musemwa
7162 POSTS0 COMMENTS
Thapelo Manthata
6861 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS