Lambda can have different meanings depending on who you're talking to or what you're talking about. In the context of JavaScript it usually refers to an anonymous function. That is a function that doesn't get named, but is usually used as a value passed to another function in order pass a behavior as a value. Here's an example. The Array.prototype.sort() function sorts an array. You can pass a function to define how to sort. In this example we are sorting by the name property of the object. In this example the lambda is a function that will receive 2 parameters (the 2 items to compare for the sort) and it should return a numeric value (negative for a before b, 0 for equal, positive for a after b) ```javascript var names = [ {name: "Jim Hoskins", id: 1}, {name: "Guil Hernandez", id: 2}, {name: "Ben Jakuben", id:3} ]; names.sort(function (a, b) { if (a.name < b.name) { return -1; } else if (a.name > b.name) { return 1; } else { return 0; } }); ``` Generally we refer to them as "anonymous functions" in JavaScript, but in this case lambda would be a synonym. Answer from Jim Hoskins on teamtreehouse.com
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › lambda-expressions-in-javascript
Lambda Expressions in JavaScript - GeeksforGeeks
December 20, 2025 - Short functions: When you need simple one-liners. Callbacks: For example, in array methods like .map(), .filter(), .reduce().
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › define lambda function handler in node.js
Define Lambda function handler in Node.js - AWS Lambda
This page describes how to work ... an example of a Node.js Lambda function that takes in information about an order, produces a text file receipt, and puts this file in an Amazon Simple Storage Service (Amazon S3) bucket....
Discussions

What is a Lambda in Javascript ?
Lambda in JavaScript ? Can anyone tell me an example of one and why we should use them. ... Lambda can have different meanings depending on who you're talking to or what you're talking about. In the context of JavaScript it usually refers to an anonymous function. More on teamtreehouse.com
🌐 teamtreehouse.com
1
June 11, 2013
jquery - JavaScript lambda functions - Stack Overflow
I was looking to have a good example for using lambda functions or anonymous functions within JavaScript with no luck. Does jQuery have built-in functions to implement lambda too? More on stackoverflow.com
🌐 stackoverflow.com
[AskJS] Why are lambda functions called lambda functions everywhere except in JS
in JS both arrow functions and non-arrow functions can be used as lambda functions. Arrow ones are more convenient for the task, but aren’t equivalent with the concept itself. More on reddit.com
🌐 r/javascript
36
2
March 18, 2025
Need example of calling AWS Lambda from JavaScript - Stack Overflow
Just need an example of how to call AWS Lambda from JavaScript running in a browser and display function result in JavaScript console. Incredibly, I cannot find any examples on Google or from AWS More on stackoverflow.com
🌐 stackoverflow.com
People also ask

Why does JavaScript use so many lambda functions?
JavaScript uses many arrow functions because they simplify code, handle this binding better, and fit well with functional programming styles.
🌐
hevodata.com
hevodata.com › home › learn › data strategy
JavaScript Lambda Functions Simplified 101 | Hevo
Why use the lambda function?
Lambda (arrow) functions are used for conciseness, lexical this binding, and aligning with functional programming practices.
🌐
hevodata.com
hevodata.com › home › learn › data strategy
JavaScript Lambda Functions Simplified 101 | Hevo
Can I use lambda in JavaScript?
Yes, you can use lambda functions in JavaScript. They are supported in modern web browsers and can be used in a variety of contexts, such as event handlers, higher-order functions, and arguments for other functions.
🌐
boltic.io
boltic.io › home › blog › lambda function javascript
Lambda Function Javascript 2026: Key Features, Use Cases, Benefits, ...
🌐
Hevo
hevodata.com › home › learn › data strategy
JavaScript Lambda Functions Simplified 101 | Hevo
December 27, 2023 - The call to the lambda L is synchronous when a lambda expression (let’s call it L) is supplied as an argument to a function (let’s call it F), and the lambda L is run by function F instantly before the function F returns. So far, the Javascript lambda example in this guide have all been ...
🌐
Vintasoft
vintasoftware.com › blog › javascript-lambda-and-arrow-functions
JavaScript lambda expressions: a quick guide
May 19, 2025 - In JavaScript, you can make a one line Javascript anonymous lambda function with arrow functions: ... An arrow function is concise and convenient, providing a shorter syntax for anonymous functions. Here's another example of similar functionality, but now with multiple lines:
🌐
Joshdata
joshdata.me › lambda-expressions.html
Lambda Expressions: A Guide
Here is a regular function (not ... and Java (they all happen to be identical in this case) and in Javascript. We’ll look at how the same function would be written as a lambda expression. ... In this example, there is a single argument x, the expression x + 1 is computed, ...
Find elsewhere
🌐
AWS
docs.aws.amazon.com › aws sdk for javascript › developer guide for sdk version 3 › sdk for javascript (v3) code examples › lambda examples using sdk for javascript (v3)
Lambda examples using SDK for JavaScript (v3) - AWS SDK for JavaScript
Shows how to create an Amazon EventBridge scheduled event that invokes an AWS Lambda function. Configure EventBridge to use a cron expression to schedule when the Lambda function is invoked. In this example, you create a Lambda function by using the Lambda JavaScript runtime API.
🌐
Medium
medium.com › @chineketobenna › lambda-expressions-vs-anonymous-functions-in-javascript-3aa760c958ae
Lambda Functions Vs Anonymous Functions in JavaScript. | by Chineke Tobenna | Medium
July 27, 2021 - On the other hand, lambda expressions are abstractions which enable a function to be passed around like data. In JavaScript, everything can be treated as an object, this means that a function can be sent into another function as a parameter and can also be retrieved from the called function as a return value. An example of lambda expression is as shown below.
🌐
Boltic
boltic.io › home › blog › lambda function javascript
Lambda Function Javascript 2026: Key Features, Use Cases, Benefits, Tips & Best Practices
January 16, 2026 - For example, you can use a lambda function to calculate the product of an array of numbers. ... You can use lambda functions as event handlers in JavaScript, allowing you to specify the behaviour of an element when a specific event occurs.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Functions › Arrow_functions
Arrow function expressions - JavaScript - MDN Web Docs
February 21, 2026 - Arrow function expressions should only be used for non-method functions because they do not have their own this. Let's see what happens when we try to use them as methods: ... "use strict"; const obj = { i: 10, b: () => console.log(this.i, this), c() { console.log(this.i, this); }, }; obj.b(); // logs undefined, Window { /* … */ } (or the global object) obj.c(); // logs 10, Object { /* … */ } Another example involving Object.defineProperty():
Top answer
1 of 2
23

In JavaScript these are called function expressions (using function as an operator as opposed to declarations, using function as a statement), and can be named or anonymous.

It's really as simple as doing something that tells the compiler it is an expression (e.g. var x =) then writing a function normally, and adding a delimiter ; on the end.

function invoke(lam) {
    console.log(
        lam()
    );
}

var lambda = function () {return 'foo';};

invoke(lambda); // "foo" logged

As with any function in JavaScript, the scope is inherited from where it is defined, not where it is invoked.

Self-invoking and anonymous functions are nearly always function expressions. For self-invoking functions, the ( before function means the code is interpreted as an expression, then the (preferred) ()); or (alternate) )(); invokes it immediately.

You may need to remember that a function expression by itself is not hoisted. If you need hoisting for it to avoid a Reference Error, combine with var. The function itself will still not be fully available until the code passes the line where it is defined.

For a named function expression the name is only available inside the function and not outside (some old versions of IE leaked the name though). To describe this, I'll use two examples, one self invoking and one vard;

// self-invoked
(function foo() {
    console.log('inside:', foo); // foo is defined here
}());
console.log('outside:', foo); // ReferenceError: foo is not defined

// var
var bar = function foobar() {
    console.log('inside:', foobar); // foobar is defined here
    console.log('inside:', bar); // bar is defined here too (=== foobar)
};
bar(); // invoke
console.log('outside:', bar); // bar is also defined here, but..
console.log('outside:', foobar); // ReferenceError: foobar is not defined
2 of 2
16

A lambda function (anonymous function) is really just a function declaration without a name (it can be assigned to a variable later and still technically be a lambda). One common example is a self-executing function:

(function(){
  /*
    do stuff
  */
})();

Another common example is passing a function as a parameter for an AJAX or JSONP callback, a timeout, or a sort():

setTimeout(
    function() {
        console.log('lambda!');
    },
    100
);

On the "receiving" end of a lambda, you invoke the function parameter as you would any other function:

functionThatUsesLamba(function(s) { console.log(s); });

function functionThatUsesLambda(logFn) {
  if (typeof(logFn) == 'function') {
    logFn('lambda');
  } else {
    throw "logFn must be a function!!!";
  }
}
🌐
Delft Stack
delftstack.com › home › howto › javascript › lambda function javascript
JavaScript Lambda Function | Delft Stack
March 11, 2025 - Unlike traditional function ... context of the parent scope. ... In this example, add is a lambda function that takes two parameters, a and b, and returns their sum....
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js
Building Lambda functions with Node.js - AWS Lambda
For more information about using ... SDK for JavaScript ... For Node.js runtime versions up to Node.js 18, Lambda automatically loads Amazon-specific CA (certificate authority) certificates to make it easier for you to create functions that interact with other AWS services. For example, Lambda includes ...
🌐
Medium
medium.com › @wwdhfernando › introduction-to-aws-lambda-and-a-simple-javascript-example-6002940471fe
Introduction to AWS Lambda and a Simple JavaScript Example | by Dilshan Fernando | Medium
January 16, 2025 - This function is triggered by an API Gateway event. Let’s create a simple AWS Lambda function that processes a JSON payload and returns a greeting message.
🌐
GeeksforGeeks
geeksforgeeks.org › python › js-equivalent-to-python-lambda
Js equivalent to Python Lambda - GeeksforGeeks
August 5, 2025 - In JavaScript, the closest equivalent to Python’s lambda function is the arrow function. Arrow functions were introduced in ES6 (ECMAScript 2015) and provide a concise syntax for defining anonymous functions.
Top answer
1 of 5
12

Since you need to run Lambda from the browser, you have two options you can achieve it.

  1. Use AWS Javascript SDK, set it up with user via static configuration or Cognito with IAM Permissions to your Lambda. You can also consider subscribing your Lambda functions to SNS Topic and run the Lambda by sending a message to the topic. This SNS approach would also require you to store and retrieve the submission state via separate call.

  2. Use AWS API Gateway to create RESTful endpoint with proper CORS configuration that you can ping from the browser using AJAX.

Both options have their pros and cons. More information about your use-case would be necessary to properly evaluate which one suits you best.

2 of 5
10

I see people have used AWS SDK for Javascript but it is not required specially since you need to create Amazon Cognito identity pool with access enabled for unauthenticated identities (Atleast for beginners like me). Below code works fine for me -

<html>
    <head>
<script>
    function callAwsLambdaFunction() {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("myDiv").innerHTML = this.responseText;
            }
        };
        xhttp.open("GET", "https://test123.ap-south-1.amazonaws.com/dev", true);
        xhttp.send();

    }
    </script>   
        <title>Hello World!</title>
    </head>
    <body>
        <h1>Hello world!</h1>
        <h1>Click below button to call API gatway and display result below!</h1>
        <h1><div id="myDiv"></div></h1>
        <button onclick="callAwsLambdaFunction()">Click me!</button><br>
        Regards,<br/>
        Aniket
    </body>
</html>

Above is sample index.html that I have added to my S3 bucket and made a static site. Couple of points to note -

  1. Make your index.html open from outside if you are using S3 for static site hosting.
  2. Make sure you turn on CORS for your API gateway if your website domain is not same as API gateway domain. Else you might get -

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://test123.ap-south-1.amazonaws.com/dev. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).

Top answer
1 of 2
6

Wikipedia says "In computer programming, an anonymous function (function literal, lambda abstraction, lambda function, lambda expression or block) is a function definition that is not bound to an identifier."

This makes things relatively easy. For your purposes, "lambda function" and "anonymous function" are effectively synonymous. Therefore, everything you express via the => syntax is a lambda function/anonymous function, and everything you define with the function syntax isn't.

A callback is simply code that is passed to other code to be called at some later time. As you've seen, you can use both named and unnamed functions as callbacks.

The important thing to remember is that "callback" is a role that a function takes on in a specific context. It's entirely possible to call a function as a normal function and also use it as a callback elsewhere.

2 of 2
3

Callback

A Callback function is any function passed as a parameter to another function to be executed when some condition occurs. In your example, when the Promise returned by fetch is fulfilled.

A callback may be anonymous or named, or defined using function or () => {}.

That is, I would define a callback as 'a function that is called else where in your application'. By that definition, the lambda functions passed into an Array.prototype method are callback functions.

Yup! The first parameter to Array.prototype.forEach is even named callbackFn.

Anonymous vs lambda

In software engineering in general, a lambda function and an anonymous function are the same thing. Here is the definition of anonymous function from the C2 wiki.

In a programming language, an unnamed function object (also: "function literal").

Example (in PseudoCode): "lambda(x,y){ x>y }" is an anonymous function object representing the function that tells whether its first argument is greater than its second argument.

A lambda function is understood to be the same thing because of lambda calculus, which involves anonymous functions, and because the lambda keyword is often used in specific language constructs implementing support for anonymous functions.

When we drill down a bit into Javascript specifically, there are two language constructs that implement anonymous functions.

The first one is an anonymous function expression

function() { console.log("Doing stuff") }

The second is an arrow function expression

() => console.log("Doing stuff")

While these provide language support for making anonymous functions, you can still assign names to the result.

const myFunction = function() { console.log("Doing stuff") }

In other languages, such as Java and C#, lambda function refers to a syntax similar to arrow functions. While Javascript doesn't really have a language construct with that name, arrow functions would probably spring to mind for many people because of the similarity.

In conclusion, anonymous functions and lambda functions can be said to be the same thing from a software engineering perspective, but they can also refer to specific language constructs which are not equivalent.

The code below

function printCurrentValue(value) {
    console.log("the value is: " + value)
}

Is then not an anonymous function, nor a lambda function. But if it had been

const printCurrentValue = function(value) {
    console.log("the value is: " + value)
}

Then it's still not an anonymous function, but you could say it's defined using an anonymous function expression.

As for

fetch('/user')
.then((res) => res.json())
.then((json) => console.log(json)); 

(res) => res.json() is

  • Anonymous
  • A callback
  • An arrow function

And you could say it's a lambda function, both referring to it being anonymous and referring to it being an arrow function.

🌐
Spinspire
spinspire.com › learn › course › js-apps › ES6 › arrow-functions
Arrow Functions/Lambda Expressions | SpinSpire Learning
The first apply call will produce what you expect, second one won't. const f1 = function (param) { console.log("this", this); console.log("param", param); } const f2 = (param) => { console.log("this", this); console.log("param", param); } // first param to `apply` is `this`, second param is ...
🌐
AWS
docs.aws.amazon.com › aws sdk code examples › code library › code examples by sdk using aws sdks › code examples for sdk for javascript (v3) › lambda examples using sdk for javascript (v3)
Lambda examples using SDK for JavaScript (v3) - AWS SDK Code Examples
Shows how to create an Amazon EventBridge scheduled event that invokes an AWS Lambda function. Configure EventBridge to use a cron expression to schedule when the Lambda function is invoked. In this example, you create a Lambda function by using the Lambda JavaScript runtime API.