Lambda Expressions
In the past, when writing a function in JavaScript, we would tell the program we were doing so by using the word function and then giving it a name. We would then declare anything that was passed into the function that we would be using in the function. Inside the function, there were many things you could do and then return some sort of data. Lambda expressions work similarly but have a few key differences. First off, lambda expressions create functions with no name. This was done well before ES6 by assigning it to a variable. Since ES6, programmers have the use of the arrow function syntax (=>).
Lambda expressions are used in JavaScript in many ways. They are powerful within a little code snippet. Arrow function versions have a few ways to write them which gives versatility in syntax and some great features. For instance, if you are passing only one variable, you don’t need the parenthesis around it. Also, “return” can be an optional keyword. Even those curly braces are optional in one-liner code.
They are even available to be stored on Amazon Web Servers (AWS) and called, like many modules are in apps, when they are needed and can scale with the usage and spawn more instances when it gets too big. They call this serverless, even though there are servers involved, they are just stored on a local server.
Get Ace D Baugh’s stories in your inbox
Join Medium for free to get updates from this writer.
With great power comes great pitfalls as well. Objects can’t be returned just as simply as they were before, they need to be encased in another layer of parenthesis. Built-in functions call() and apply() don’t have the power to provide another value for the keyword “this” which you can’t change either.
Overall, lambda expressions can create some amazing and powerful functions that can be used in many situations and scale with your project as need dictates.
References
Ericson, A. (2015, December 14). JavaScript’s lambda and Arrow Functions. Python, Django and React Web Development Experts. Retrieved August 30, 2022, from https://www.vinta.com.br/blog/2015/javascript-lambda-and-arrow-functions/
Stojanovic, S. (2018, October 20). Express.js and Aws Lambda — A serverless love story. Medium. Retrieved August 30, 2022, from https://medium.com/free-code-camp/express-js-and-aws-lambda-a-serverless-love-story-7c77ba0eaa35




