JavaScript -A Lamda Function


The next method is not an actual method or an operator, but a style of writing a function.  In the past, I would usually write something like this:

function myFunction() {

//do something here


However, like other languages, JavaScript allows you to write one line methods called Lambda’s.  This is useful for chaining .then() clauses to asynchronous code involving callbacks and/or Promises.  In the sample below, I write a Lambda method logging the contents of each array element:

array.forEach((arrayElement => console.log(arrayElement));

myComplexObjectArray.forEach((arrayElement) => console.log(JSON.stringify(arrayElement)));


Stay tuned!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s